473,545 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Validation of fields in a form

89 New Member
I have a problem with some validation of some fields in a form.

I have some fields that only become visible if a specific field is chosen.

For example:

[HTML]<select name="u_global_ __delivery_form " onchange="docum ent.getElementB yId('array_div' ).style.display =(this.selected Index>1)?'block ':'none';" >
<option value="0" selected="selec ted"></option>
<option value="Single board">Single board</option>
<option value="Array">A rray</option>
</select>[/HTML]

Where if you select the "array" option in my form, additional fields become visible:

[HTML]<div id="array_div" style="display: none;">
<table width="100%" border="1" cellspacing="0" cellpadding="0" style="border-style:none;">
<tr>
<td height="25" align="center" valign="top" colspan="3" style="padding-top: 5px; padding-bottom: 0px; border-style:none;"><i mg src="../images/array.gif"></td>
</tr>
<tr>
<td width="44%" align="right" valign="top" style="padding-right: 5px; padding-top: 5px; border-style:none;">Ar ray size X</td>
<td width="50%" align="left" valign="top" style=" padding-top: 5px; border-bottom-style:none; border-left-style:none; border-right-color:#E0A70D; border-top-style:none;"><i nput name="u_subpane l___array_x" type="text" size="15"></td>
</tr>
<tr>
<td align="right" valign="top" style="padding-right: 5px; border-style:none;">Ar ray size y</td>
<td align="left" valign="top" style="border-bottom-style:none; border-left-style:none; border-right-color:#E0A70D; border-top-style:none;"><i nput name="u_subpane l___array_y" type="text" size="15"></td>
</tr>
<tr>
<td align="right" valign="top" style="padding-right: 5px; border-style:none;">Bo ards per array X</td>
<td align="left" valign="top" style="border-bottom-style:none; border-left-style:none; border-right-color:#E0A70D; border-top-style:none;"><i nput name="u_subpane l___array_num_x " type="text" size="15"></td>
</tr>
<tr>
<td align="right" valign="top" style="padding-right: 5px; border-style:none;">Bo ards per array y</td>
<td align="left" valign="top" style="border-bottom-style:none; border-left-style:none; border-right-color:#E0A70D; border-top-style:none;"><i nput name="u_subpane l___array_num_y " type="text" size="15"></td>
</tr>
<tr>
<td align="right" valign="top" style="padding-right: 5px; border-style:none;">Bo ard seperation</td>
<td align="left" valign="top" style="border-bottom-style:none; border-left-style:none; border-right-color:#E0A70D; border-top-style:none;"><s elect name="u_subpane l___board_sep">
<option selected="selec ted"></option>
<option value="Break routing">Break routing</option>
<option value="Scoring" >Scoring</option>
<option value="Break routing+Scoring ">Both</option>
</select> </td>
</tr>
<tr>
<td align="right" valign="top" style="padding-right: 5px; border-bottom-color:#E0A70D; border-left-style:none; border-right-style:none; border-top-style:none;">Pa sta data required</td>
<td align="left" valign="top" style="border-left-style:none; border-right-color:#E0A70D; border-bottom-color:#E0A70D; border-top-style:none;"><i nput onClick="javasc ript:getDiv6(); " name="u_subpane l___pasta_req" type="radio" value="No" style="border-style:none;">No &nbsp;&nbsp;<in put name="u_subpane l___pasta_req" id="tin_array" type="radio" value="Yes" style="border-style:none;" onClick="javasc ript:getDiv6(); ">Yes</td>
</tr>
</table>
</div>[/HTML]

Now, my problem is to only validate on the newly visible fields, when the user selects the "array" option and no validation if the fields do not become visible.

Please help.........

Thanks very much in advance.
Feb 20 '07 #1
16 2431
dmjpro
2,476 Top Contributor
can't u check the display style which is to be validated
Feb 20 '07 #2
printline
89 New Member
can't u check the display style which is to be validated
Not sure exactly what you mean by that. Can you give me an example....?
Feb 20 '07 #3
acoder
16,027 Recognized Expert Moderator MVP
Use
Expand|Select|Wrap|Line Numbers
  1. document.getElementById("id").style.property
to get the style property of the object where "id" is the id of the object and property should be (in this case) "display".
Feb 20 '07 #4
dmjpro
2,476 Top Contributor
suppose u have ...
<input id = id_name>

in js .... write
if(document.get ElementById('id _name').style.d isplay == 'block')
/do validation

is this what u need
Feb 20 '07 #5
printline
89 New Member
suppose u have ...
<input id = id_name>

in js .... write
if(document.get ElementById('id _name').style.d isplay == 'block')
/do validation

is this what u need
I think so, but i can't get it working

I have done the following:

if(document.get ElementById('ar ray_div').style .display = "block")
var frmvalidator = new Validator("main form");
frmvalidator.ad dValidation("u_ subpanel___arra y_x","req","Ple ase type in array x dimension");
frmvalidator.ad dValidation("u_ subpanel___arra y_x","alnumhyph en");

But it doesn't validate on the field u_subpanel___ar ray_x when the div id array_div is visible in my form
Feb 20 '07 #6
acoder
16,027 Recognized Expert Moderator MVP
I think so, but i can't get it working

I have done the following:

Expand|Select|Wrap|Line Numbers
  1. if(document.getElementById('array_div').style.display = "block")
  2. var frmvalidator  = new Validator("mainform");
  3. frmvalidator.addValidation("u_subpanel___array_x","req","Please type in array x dimension");
  4.   frmvalidator.addValidation("u_subpanel___array_x","alnumhyphen");
But it doesn't validate on the field u_subpanel___ar ray_x when the div id array_div is visible in my form
That should be double equals:
Expand|Select|Wrap|Line Numbers
  1. if(document.getElementById('array_div').style.display == "block")
Feb 20 '07 #7
printline
89 New Member
That should be double equals:
Expand|Select|Wrap|Line Numbers
  1. if(document.getElementById('array_div').style.display == "block")
It still doesn't work even with double equals. Here is the code i use:

[HTML]<select id="test" name="u_global_ __delivery_form " onchange="docum ent.getElementB yId('array_div' ).style.display =(this.selected Index>1)?'block ':'none';">
<option value="0" selected="selec ted"></option>
<option value="Single board">Single board</option>
<option value="Array">A rray</option>
</select>
<div id="array_div" style="display: none;">
<table width="100%" border="1" cellspacing="0" cellpadding="0" style="border-style:none;">
<tr>
<td width="44%" align="right" valign="top">Ar ray size X <font color="#FF0000" >*</font></td>
<td width="50%" align="left" valign="top"><i nput name="u_subpane l___array_x" type="text" size="15"></td>
</tr>

<tr>
<td align="right" valign="top">Ar ray size y</td>
<td align="left" valign="top"<in put name="u_subpane l___array_y" type="text" size="15"></td>
</tr>
</table>
</div>

<script language="JavaS cript" src="gen_valida torv2.js" type="text/javascript">
</script>


<script language="JavaS cript" type="text/javascript">
var frmvalidator = new Validator("main form");
frmvalidator.ad dValidation("u_ global___delive ry_form","donts elect=0","Pleas e choose delivery form");
if(document.get ElementById('ar ray_div').style .display == "block")
frmvalidator.ad dValidation("u_ subpanel___arra y_x","req","Ple ase fill in array x");
frmvalidator.ad dValidation("u_ subpanel___arra y_y","req","Ple ase fill in array x");[/HTML]
Please post in code tags - moderator
Feb 23 '07 #8
acoder
16,027 Recognized Expert Moderator MVP
You need a code block after the if because you are checking for both x and y if the display style is block. Also, you have a typo - instead of y you had x for the second error message:
Expand|Select|Wrap|Line Numbers
  1. var frmvalidator  = new Validator("mainform");
  2. frmvalidator.addValidation("u_global___delivery_form","dontselect=0","Please choose delivery form");
  3. if(document.getElementById('array_div').style.display == "block") {
  4.   frmvalidator.addValidation("u_subpanel___array_x","req","Please fill in array x");
  5.   frmvalidator.addValidation("u_subpanel___array_y","req","Please fill in array y");
  6. }
Feb 23 '07 #9
printline
89 New Member
You need a code block after the if because you are checking for both x and y if the display style is block. Also, you have a typo - instead of y you had x for the second error message:
Expand|Select|Wrap|Line Numbers
  1. var frmvalidator  = new Validator("mainform");
  2. frmvalidator.addValidation("u_global___delivery_form","dontselect=0","Please choose delivery form");
  3. if(document.getElementById('array_div').style.display == "block") {
  4.   frmvalidator.addValidation("u_subpanel___array_x","req","Please fill in array x");
  5.   frmvalidator.addValidation("u_subpanel___array_y","req","Please fill in array y");
  6. }
It still skips the validation of the two fields u_subpanel___ar ray_x and u_subpanel___y if the array option is chosen from the u_global___deli very_form filed. Any suggestions on what is wrong.......... .??????
Feb 23 '07 #10

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

Similar topics

4
2619
by: bnp | last post by:
Hi All, I am quite new the JavaScript. Basically I am a C++ programmer, but now I am working on JavaScript since last 5 days. I have a problem regarding the form validation. I have created a script that validates the form fields. the validation procedure is called ONCLICK event of the submit button. Follwowing is the structure of the...
5
2580
by: EviL KerneL | last post by:
Hi - I am trying to figure out a way to enforce the validation included for this form based on whether the user chooses "email" or "phone" as the contact choice. Right now it is set to enforce validation on both. Is there a way to link the drop-down choice to the correspondent validation section while disabling validation for the other...
16
2202
by: Hosh | last post by:
I have a form on a webpage and want to use JavaScript validation for the form fields. I have searched the web for form validation scripts and have come up with scripts that only validate individual fields, such as an "Email Validation Script" or a "Phone Validation Script". Is it ok to put all these scripts on page as they are or should they...
3
15903
by: Dalan | last post by:
I apparently need a bit of assistance regarding the structure of some validation code on the BeforeUpdate or AfterUpdate event on a form for several fields that need to controlled. I did search the archives, but found nothing precise enough to address my specific needs. 1. There are three text box fields on the form and one of the three...
1
3243
by: IkBenHet | last post by:
Hello, Currently I am using a large input form on a website that is based on ASP and JavaScript. Depending on the values that are filled in by the user the forms does a refresh and makes other input fields available to fill in. I use the JavaScript OnChange function (=clientside) that creates a querystring and does a refresh of the page....
1
1808
by: Buddy Ackerman | last post by:
I don't know what the problem is. I have a form with several controls that need to be validated, I put a validation group in every form control, every validatoino control, the submit button and the validation summary control. I want it to do client side validation so I set every validation control display property to none and set the...
9
4158
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 honest I usually hire someone to do it for me, grab predone scripts and kind of hack out the parts that I need, or just do very minimal validation...
7
6973
by: h7qvnk7q001 | last post by:
I'm trying to implement a simple server-side form validation (No Javascript). If the user submits a form with errors, I want to redisplay the same form with the errors highlighted. Once the form is correct I need to submit to another page that uses the form data. I first tried making the form submit action= field point to the same file....
11
2967
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 certain fields match certain criteria, and inform the user in different ways when the data is wrong (offcourse, this will be checked on posting the...
12
2465
by: Gustaf | last post by:
I've been working on a membership form for a while, and find it very tedious to get an acceptable level of form validation. A web search for solutions revealed some home-brewed solutions, such as these: http://simonwillison.net/2003/Jun/17/theHolyGrail/ http://samuelsjoberg.com/archive/2004/11/form-validation-on-client-and-server Quoting...
0
7420
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7680
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7446
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6003
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5349
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3476
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3459
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1908
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 we have to send another system
0
731
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.