473,499 Members | 1,579 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to getElementByType and check validation using javascript.

24 New Member
Hello guys,
I met a problem about php and javascipt
For a tickets booking system, when a customer search for flights from one city, so in the data base there should be many routes to different cities, like from Sydney, it can go to Landon, Paris and Beijing and etc. So first I use php to get the data from data base, and use a loop to list all of them and after each route, there is a input field which type is text for the customer to enter the tickets quantities they want to by, and I name the input fields by using the loop, from i=1 to i='number of records' . Now the problem is I have to check the validation of the entered quantities be from 1 to 6, which means the customer just can buy six tickets for one routes. how can I get the variables from the form, because I also use some inputs fields to transfer other data.this is how I define the input fields in php:[PHP] print "<input type=\"text\" id=\"$i\" name=\"ticket_$i\" size=\"3\" value=\"\">";[/PHP]
How can I use Javascript to check the validation of this fields?

Many thanks first.
Sep 24 '07 #1
6 92342
lucoin
24 New Member
I mean if I use getElementByType('text'), what variables I will get. Thank you.
Sep 24 '07 #2
gits
5,390 Recognized Expert Moderator Expert
hi ...

as far as i know there is no standard dom method that is called getElementsByType() ... so you have to implement it or may be you have copied one for you ... the standard way is to use:

Expand|Select|Wrap|Line Numbers
  1. var node_list = document.getElementsByTagName('input');
  2.  
  3. for (var i = 0; i < node_list.length; i++) {
  4.     var node = node_list[i];
  5.  
  6.     if (node.getAttribute('type') == 'text') {
  7.         // do something here with a <input type="text" .../>
  8.         // we alert its value here
  9.         alert(node.value);
  10.     }
  11.  
kind regards
Sep 24 '07 #3
lucoin
24 New Member
hi ...

as far as i know there is no standard dom method that is called getElementsByType() ... so you have to implement it or may be you have copied one for you ... the standard way is to use:

Expand|Select|Wrap|Line Numbers
  1. var node_list = document.getElementsByTagName('input');
  2.  
  3. for (var i = 0; i < node_list.length; i++) {
  4.     var node = node_list[i];
  5.  
  6.     if (node.getAttribute('type') == 'text') {
  7.         // do something here with a <input type="text" .../>
  8.         // we alert its value here
  9.         alert(node.value);
  10.     }
  11.  
kind regards
Thank you, it works very well. But one more thing, how can I get how many 'text' fields there?
Sep 24 '07 #4
gits
5,390 Recognized Expert Moderator Expert
hi ...

we may write a get_textboxes method like this:

Expand|Select|Wrap|Line Numbers
  1. function get_textboxes() {
  2.     var node_list = document.getElementsByTagName('input');
  3.     var textboxes = [];
  4.  
  5.     for (var i = 0; i < node_list.length; i++) {
  6.         var node = node_list[i];
  7.  
  8.         if (node.getAttribute('type') == 'text') {
  9.             textboxes.push(node);
  10.         }
  11.     } 
  12.  
  13.     return textboxes;
  14. }
  15.  
so now you call the function and you get an array with textboxes out of it, and you can ask for its length.

kind regards
Sep 24 '07 #5
Thanks, it worked like a charm!
cheers man...
Nov 6 '10 #6
ramonlm
1 New Member
Beautiful... Many thanks!!!
Mar 3 '16 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

8
14628
by: Edo van der Zouwen | last post by:
It's quite easy in Php: <?php $language = $_SERVER; $language_short = substr($taal,0,2); echo $language_short; ?>
2
5068
by: trusst_3 | last post by:
Hello, This is the only line in my entire code that does not validate in XHTML : <td width="24" bgcolor="#330066" onclick="javascript:color1()" class="borderWidthr"></td> However, it is...
0
1854
by: ED M. | last post by:
Hello all...I'm new to the board. I have a problem that I hope someone here might be able to solve for me. I am doing some clientside validation using Javascript. The text I am testing is...
6
27891
by: prabhunew2005 | last post by:
Hi all, I need to allow the date format only yyyy-mm-dd to store into mysql4 data base. I have the validation coding for mm-dd-yyyy format. But i could not modify to convert it to...
1
2015
by: etsomik | last post by:
Hi guys. I need some help in javascript. I wrote a function which supposed to validate the date. And it does working it addin slashes as you type that what I want, However now I need to display a...
2
2161
by: nbt725 | last post by:
Dear Sir, Hello ! I need to validate my login form which is displayed using <div> to give sliding effect and not to refresh page, hence can't use generic php submit but to validate using...
1
2219
by: printline | last post by:
Hello All I'm a newbee to javascript/ajax. I have produced a form, where i want to do some validation on some fields. I have used the spry framework and it works fine. Now, i have a select...
1
2141
by: scott | last post by:
Hello, Thanks in advance for any help you might be able to offer... I have an html table with two columns and 10 rows. The first column contains a textbox that is populated. The second column...
9
35640
mageswar005
by: mageswar005 | last post by:
Hi Guys, My array textbox validation is not working fine,my code is given below please help me immediately. function validation() { var chks =...
0
7007
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6893
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7386
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5468
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4918
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4599
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
664
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
295
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.