473,503 Members | 6,587 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Form validation using javascript

89 New Member
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 list, where if i choose a certian option, more fields in the form will appear.

My problem is only to validate on these fields if they are visible. I think that maybe some if - else statements will do the trick, but how do i implement these....?

Here is my code:

My select list:

[HTML]<select name="Delivery_form" id="Delivery_form" onchange="document.getElementById('array_div').sty le.display=(this.selectedIndex>1)?'block':'none';" >
<option selected="selected" value="">Select delivery form</option>
<option value="Single">Single board</option>
<option style="background-color: #4cabcb;" value="Array">Array</option>
</select>[/HTML]

The extra fields:

[HTML]<div id="array_div" style="display:none;">
<span id="delivery_form">
<table width="100%" border="1" style="border-style: none;" bordercolor="#005876" cellspacing="0" cellpadding="0">
<tr>
<td><select name="Board_seperation" size="1" style="background-color: #ffff99;">
<option selected="selected">--Please choose--</option>
<option value="Break routing">Break routing</option>
<option value="Scoring">Scoring</option>
<option value="Break routing+Scoring">Both</option>
</select></td>
</tr>
</table>
</span>
<span id="Array_size_x">
<table width="100%" border="1" style="border-style: none;" bordercolor="#005876" cellspacing="0" cellpadding="0">
<tr>
<td><input name="Array_size_x" type="text" size="8" style="background-color: #ffff99;"></td>
</tr>
</table>
</span>
<span id="Pasta_data">
<table width="100%" border="1" style="border-style: none;" bordercolor="#005876" cellspacing="0" cellpadding="0">
<tr>
<td><select name="Pasta_data" size="1">
<option selected="selected" value="No">No</option>
<option value="Yes">Yes</option>
</select></td>
</tr>
</table>
</span>
<span id="Boards_per_array_x">
<table width="100%" border="1" style="border-style: none;" bordercolor="#005876" cellspacing="0" cellpadding="0">
<tr>
<td><input name="Boards_per_array_x" type="text" size="8" style="background-color: #ffff99;"></td>
</tr>
</table>
<span>
</div>[/HTML]

Javascript validation:

Expand|Select|Wrap|Line Numbers
  1. var delivery_form = new Spry.Widget.ValidationSelect("delivery_form", {validateOn:["change"]});
  2. var Board_seperation = new Spry.Widget.ValidationSelect("Board_seperation", {validateOn:["change"]});
  3.     var board_size_x = new Spry.Widget.ValidationTextField("Board_size_x", "real", {useCharacterMasking:true, validateOn:["change"]});
  4.     var Array_size_x = new Spry.Widget.ValidationTextField("Array_size_x", "real", {useCharacterMasking:true, validateOn:["change"]});
  5.     var Pasta_data = new Spry.Widget.ValidationSelect("Pasta_data", {validateOn:["change"]});
Mar 12 '08 #1
1 2219
acoder
16,027 Recognized Expert Moderator MVP
Yes, an if statement should do fine:
Expand|Select|Wrap|Line Numbers
  1. // elem is an element to be validated if visible
  2. if (elem.style.display == "block") {
  3. // validate
  4. } // no need for else.
Mar 12 '08 #2

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

Similar topics

5
4246
by: TG | last post by:
Dear PHP Group, I have two forms that are used to collect user information. The first one takes user inputted values such as fullname, city, address etc. I want these values to display in the...
5
2119
by: Danny | last post by:
Does anybody have a nice method of forcing a user to enter a value into a form using asp? I think the best is to have a popup when they hit submit that will stay on the same page and then just...
3
2896
by: wk6pack | last post by:
Hi, How do you check for a empty value from a form? lservice = request.form("pservice") if not isnull(lservice) then <== this doesnt work. tried "" empty string and it still didnt work....
6
507
by: Darren | last post by:
I have a form that has 10 fields on it. I have made all of them "Required". I also am using vb if statements to decide whether or not each field should be on the page. I am using the vb to...
2
1996
by: iam247 | last post by:
Hi I have an ASP form which only includes an option list. The list is dynamically created but includes a default value, which is an instruction "Select a group". The code is shown at bottom....
9
4153
by: julie.siebel | last post by:
Hello all! As embarrassing as it is to admit this, I've been designing db driven websites using javascript and vbscript for about 6-7 years now, and I am *horrible* at form validation. To be...
27
4679
by: Chris | last post by:
Hi, I have a form for uploading documents and inserting the data into a mysql db. I would like to validate the form. I have tried a couple of Javascript form validation functions, but it...
11
2958
by: Rik | last post by:
Hello guys, now that I'm that I'm working on my first major 'open' forms (with uncontrolled users I mean, not a secure backend-interface), I'd like to add a lot of possibilities to check wether...
3
3276
uranuskid
by: uranuskid | last post by:
Hey folks, I was going to include a contact form on my website. Well, in the first place that seemed an easy thing to do with a form that prompts a PHP file validating the input vaiables and using...
1
2588
by: runway27 | last post by:
i have 3 pages page1.php page2.php and page3.php in page1.php user fills a registration form in page2.php the user can review what they have entered and make any changes and page3.php...
0
7067
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...
0
7316
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6975
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
5562
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,...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1495
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
728
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
371
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.