473,396 Members | 1,780 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Validation of fields in a form

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="document.getElementById('array_div').sty le.display=(this.selectedIndex>1)?'block':'none';" >
<option value="0" selected="selected"></option>
<option value="Single board">Single board</option>
<option value="Array">Array</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;"><img src="../images/array.gif"></td>
</tr>
<tr>
<td width="44%" align="right" valign="top" style="padding-right: 5px; padding-top: 5px; border-style:none;">Array 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;"><input name="u_subpanel___array_x" type="text" size="15"></td>
</tr>
<tr>
<td align="right" valign="top" style="padding-right: 5px; border-style:none;">Array 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;"><input name="u_subpanel___array_y" type="text" size="15"></td>
</tr>
<tr>
<td align="right" valign="top" style="padding-right: 5px; border-style:none;">Boards 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;"><input name="u_subpanel___array_num_x" type="text" size="15"></td>
</tr>
<tr>
<td align="right" valign="top" style="padding-right: 5px; border-style:none;">Boards 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;"><input name="u_subpanel___array_num_y" type="text" size="15"></td>
</tr>
<tr>
<td align="right" valign="top" style="padding-right: 5px; border-style:none;">Board seperation</td>
<td align="left" valign="top" style="border-bottom-style:none; border-left-style:none; border-right-color:#E0A70D; border-top-style:none;"><select name="u_subpanel___board_sep">
<option selected="selected"></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;">Pasta 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;"><input onClick="javascript:getDiv6();" name="u_subpanel___pasta_req" type="radio" value="No" style="border-style:none;">No&nbsp;&nbsp;<input name="u_subpanel___pasta_req" id="tin_array" type="radio" value="Yes" style="border-style:none;" onClick="javascript: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 2421
dmjpro
2,476 2GB
can't u check the display style which is to be validated
Feb 20 '07 #2
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 Expert Mod 8TB
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 2GB
suppose u have ...
<input id = id_name>

in js .... write
if(document.getElementById('id_name').style.displa y == 'block')
/do validation

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

in js .... write
if(document.getElementById('id_name').style.displa y == '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.getElementById('array_div').style.disp lay = "block")
var frmvalidator = new Validator("mainform");
frmvalidator.addValidation("u_subpanel___array_x", "req","Please type in array x dimension");
frmvalidator.addValidation("u_subpanel___array_x", "alnumhyphen");

But it doesn't validate on the field u_subpanel___array_x when the div id array_div is visible in my form
Feb 20 '07 #6
acoder
16,027 Expert Mod 8TB
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___array_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
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="document.getElementById('array_div').sty le.display=(this.selectedIndex>1)?'block':'none';" >
<option value="0" selected="selected"></option>
<option value="Single board">Single board</option>
<option value="Array">Array</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">Array size X <font color="#FF0000">*</font></td>
<td width="50%" align="left" valign="top"><input name="u_subpanel___array_x" type="text" size="15"></td>
</tr>

<tr>
<td align="right" valign="top">Array size y</td>
<td align="left" valign="top"<input name="u_subpanel___array_y" type="text" size="15"></td>
</tr>
</table>
</div>

<script language="JavaScript" src="gen_validatorv2.js" type="text/javascript">
</script>


<script language="JavaScript" type="text/javascript">
var frmvalidator = new Validator("mainform");
frmvalidator.addValidation("u_global___delivery_fo rm","dontselect=0","Please choose delivery form");
if(document.getElementById('array_div').style.disp lay == "block")
frmvalidator.addValidation("u_subpanel___array_x", "req","Please fill in array x");
frmvalidator.addValidation("u_subpanel___array_y", "req","Please fill in array x");[/HTML]
Please post in code tags - moderator
Feb 23 '07 #8
acoder
16,027 Expert Mod 8TB
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
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___array_x and u_subpanel___y if the array option is chosen from the u_global___delivery_form filed. Any suggestions on what is wrong...........??????
Feb 23 '07 #10
acoder
16,027 Expert Mod 8TB
Show your validation code.

Does the rest of the validation work?
Feb 23 '07 #11
Show your validation code.

Does the rest of the validation work?
The rest of the validation works fine. It only skips the two fields before mentioned.

<script language="JavaScript" src="gen_validatorv2.js" type="text/javascript">
</script>

<script language="JavaScript" type="text/javascript">
//You should create the validator only after the definition of the HTML form
var frmvalidator = new Validator("mainform");
frmvalidator.addValidation("cust_upload_file","req ","Please upload a file");

frmvalidator.addValidation("job___order_qty","req" ,"Please fill in board quantity");
frmvalidator.addValidation("job___order_qty","nume ric");

frmvalidator.addValidation("u_orderinfo___ship_dat e","req","Please choose a ship date");

frmvalidator.addValidation("u_orderinfo___ship_by" ,"dontselect=0","Please choose a ship by method");

frmvalidator.addValidation("job___num_layers","don tselect=0","Please choose number of layers");

frmvalidator.addValidation("job___drm_pcbx","req", "Please type in board x dimension");
frmvalidator.addValidation("job___drm_pcbx","alnum hyphen");

frmvalidator.addValidation("job___drm_pcby","req", "Please type in board y dimension");
frmvalidator.addValidation("job___drm_pcby","alnum hyphen");

frmvalidator.addValidation("job___bd_thick_pixels" ,"req","Please type in board thickness");
frmvalidator.addValidation("job___bd_thick_pixels" ,"alnumhyphen");

frmvalidator.addValidation("u_global___delivery_fo rm","dontselect=0","Please choose delivery form");

var frmvalidator = new Validator("mainform");
frmvalidator.addValidation("u_global___delivery_fo rm","dontselect=0","Please choose delivery form");
if(document.getElementById('array_div').style.disp lay == "block") {
frmvalidator.addValidation("u_subpanel___array_x", "req","Please fill in array x");
frmvalidator.addValidation("u_subpanel___array_y", "req","Please fill in array y");
}

frmvalidator.addValidation("u_material___outer_mat ","dontselect=0","Please choose board material");

frmvalidator.addValidation("u_material___outer_cu_ thk","dontselect=0","Please choose copper thickness");

frmvalidator.addValidation("u_global___chamfer","d ontselect=0","Please choose chamfer");

frmvalidator.addValidation("u_global___soldermask" ,"dontselect=0","Please choose soldermask");

frmvalidator.addValidation("u_global___legend","do ntselect=0","Please choose legend");

frmvalidator.addValidation("u_global___bluemask"," dontselect=0","Please choose peelable mask");

frmvalidator.addValidation("u_global___via_cap","d ontselect=0","Please choose via capping");

frmvalidator.addValidation("u_global___scoring","d ontselect=0","Please choose scoring");

frmvalidator.addValidation("u_global___ul_req","do ntselect=0","Please choose UL required");

frmvalidator.addValidation("job___surface_finish", "dontselect=0","Please choose a surface finish");

frmvalidator.addValidation("job___impedance_contro l","dontselect=0","Please choose impedance");

frmvalidator.addValidation("u_global___ipc_perfag" ,"dontselect=0","Please choose IPC / Perfag");


</script>
Feb 23 '07 #12
acoder
16,027 Expert Mod 8TB
Oh, I think I know what the problem is. You've copied the code exactly with the bug:
Expand|Select|Wrap|Line Numbers
  1. if(document.getElementById('array_div').style.display == "block") {
There's a bug which adds a space sometimes. It should be "display" not "disp lay".
Feb 23 '07 #13
Oh, I think I know what the problem is. You've copied the code exactly with the bug:
Expand|Select|Wrap|Line Numbers
  1. if(document.getElementById('array_div').style.display == "block") {
There's a bug which adds a space sometimes. It should be "display" not "disp lay".
I removed the space so the code says display and not dis play but it didn't make a difference. it still doesn't validate the two fields which becomes visible when the "array" option is chosen from the drop down menu "u_global___delivery_form"

<select id="test" name="u_global___delivery_form" onchange="document.getElementById('array_div').sty le.display=(this.selectedIndex>1)?'block':'none';" >
<option value="0" selected="selected"></option>
<option value="Single board">Single board</option>
<option value="Array">Array</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">Array size X</td>
<td width="50%" align="left" valign="top"><input name="u_subpanel___array_x" type="text" size="15"></td>
</tr>

<tr>
<td align="right" valign="top">Array size y</td>
<td align="left" valign="top"><input name="u_subpanel___array_y" type="text" size="15"></td>
</tr>
</table>
</div>
Feb 23 '07 #14
acoder
16,027 Expert Mod 8TB
I tested the following code by calling it on the onsubmit event handler:
Expand|Select|Wrap|Line Numbers
  1. function mytest() {
  2.  if (document.getElementById('array_div').style.display == "block") alert("test");
  3.  else alert("failed");
  4.  return false;
  5. }
and it works fine. When the div is visible, it displays "test" and when it isn't, it displays "failed".
Feb 23 '07 #15
I tested the following code by calling it on the onsubmit event handler:
Expand|Select|Wrap|Line Numbers
  1. function mytest() {
  2.  if (document.getElementById('array_div').style.display == "block") alert("test");
  3.  else alert("failed");
  4.  return false;
  5. }
and it works fine. When the div is visible, it displays "test" and when it isn't, it displays "failed".
It works now. Chose another way to do the validation because i wasn't doing it with the onsubmit event handler. But another problem came up. As it is now the validation is on the option "array". So when i choose the array option i can't submit because it gives me an alert. What it should do when the "array" option is chosen, is to validate on the newly visible fields "u_subpanel___array_x" and "u_subpanel___array_x" could you perhaps help me on that........? I have put some code for you here:

function checkform ( form )
{
if (form.u_global___delivery_form.value == "0") {
alert( "Please choose a delivery form." );
form.u_global___delivery.focus();
return false ;
}
if (document.getElementById('array_div').style.displa y == "block") {
Here, if possible, validation of two new visible fields
return false;
}
}


<select id="test" name="u_global___delivery_form" onchange="document.getElementById('array_div').sty le.display=(this.selectedIndex>1)?'block':'none';" >
<option value="0" selected="selected"></option>
<option value="Single board">Single board</option>
<option value="Array">Array</option>
</select>

<div id="array_div" style="display:none;">
<table width="100%" border="1" cellspacing="0" cellpadding="0" style="border-style:none;">
<tr>
<td>
<input name="u_subpanel___array_x" type="text" size="15">
</td>
</tr>
<tr>
<td>
<input name="u_subpanel___array_y" type="text" size="15">
</td>
</tr>
</table>
</div>
Feb 23 '07 #16
acoder
16,027 Expert Mod 8TB
Since you haven't set an id for the input boxes, you can use the names, e.g.
Expand|Select|Wrap|Line Numbers
  1. if (form.u_subpanel___array_x.value == "") {
  2.  alert("Please enter the array value x");
  3.  form.u_subpanel___array_x.focus();
  4.  return false;
  5. }
Feb 23 '07 #17

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

Similar topics

4
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...
5
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...
16
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...
3
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...
1
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...
1
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...
9
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...
7
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...
11
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...
12
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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,...
0
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...
0
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
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...

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.