|
View:
New views
4 Messages
—
Rating Filter:
Alert me
|
|
|
Applying JS to dynamically created varsHello
I need help with an issue. I am creating dynamically generated form fields so there can be 10 or 20 or 30 and so on (in groups of 10, and up to 50) I need to apply javascript validation to those fields. My question is how can I predict the number of fields there will be? I need to do things such as this: If field1 = "Null", Set field2, 3, 4, 5 to "NULL" Thank you in advance for your help and I have a AM deadline ;) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Message: http://www.houseoffusion.com/lists.cfm/link=i:33:2730 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/33 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:33 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=17837.14401.33 Donations & Support: http://www.houseoffusion.com/tiny.cfm/54 |
|
|
RE: Applying JS to dynamically created varsYou just loop over the form elements. In other words, use the form's number
of elements as your index and then use logic to determine what type of element it is. Then you just validate them accordingly. Here is an example using radio elements: <script> function checkform(obj_input) { var checked = 0; for (var i=0; i<obj_input.length; i++) { if(obj_input.elements[i].type == 'radio') { if(obj_input.elements[i].checked == true) { checked++; break; } } } if (checked == 0) { alert("you did not check a radio button"); return false; } return true; } </script> <form action="" method="post" onsubmit="return checkform(this)" name="theform"> <input type="radio" name="arad" value="true"><input type="radio" name="arad"value="false"><br /> <input type="text" name="atest" size="10"><br /> <input type="submit" value="submit"> </form> Warmest Regards, Phillip B. Holmes http://phillipholmes.com 214-995-6175 (cell) -----Original Message----- From: Torrent Girl [mailto:torrentgirl@...] Sent: Wednesday, June 14, 2006 8:35 PM To: Javascript Subject: Applying JS to dynamically created vars Hello I need help with an issue. I am creating dynamically generated form fields so there can be 10 or 20 or 30 and so on (in groups of 10, and up to 50) I need to apply javascript validation to those fields. My question is how can I predict the number of fields there will be? I need to do things such as this: If field1 = "Null", Set field2, 3, 4, 5 to "NULL" Thank you in advance for your help and I have a AM deadline ;) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Message: http://www.houseoffusion.com/lists.cfm/link=i:33:2734 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/33 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:33 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=17837.14401.33 Donations & Support: http://www.houseoffusion.com/tiny.cfm/54 |
|
|
Re: Applying JS to dynamically created varsOk thanks
I'll take a look and see how I can implement it. >You just loop over the form elements. In other words, use the form's number >of elements as your index and then use logic to determine what type of >element it is. Then you just validate them accordingly. Here is an example >using radio elements: > > ><script> >function checkform(obj_input) { > var checked = 0; > for (var i=0; i<obj_input.length; i++) { > if(obj_input.elements[i].type == 'radio') { > if(obj_input.elements[i].checked == true) { > checked++; > break; > } > } > } > if (checked == 0) { > alert("you did not check a radio button"); > return false; > } > return true; >} ></script> > > > ><form action="" method="post" onsubmit="return checkform(this)" >name="theform"> ><input type="radio" name="arad" value="true"><input type="radio" >name="arad"value="false"><br /> ><input type="text" name="atest" size="10"><br /> ><input type="submit" value="submit"> ></form> > > > >Warmest Regards, > >Phillip B. Holmes >http://phillipholmes.com >214-995-6175 (cell) > > > > > >-----Original Message----- >From: Torrent Girl [mailto:torrentgirl@...] >Sent: Wednesday, June 14, 2006 8:35 PM >To: Javascript >Subject: Applying JS to dynamically created vars > >Hello > >I need help with an issue. > >I am creating dynamically generated form fields so there can be 10 or 20 or >30 and so on (in groups of 10, and up to 50) > >I need to apply javascript validation to those fields. > >My question is how can I predict the number of fields there will be? > >I need to do things such as this: > >If field1 = "Null", Set field2, 3, 4, 5 to "NULL" > > >Thank you in advance for your help and I have a AM deadline ;) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Message: http://www.houseoffusion.com/lists.cfm/link=i:33:2744 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/33 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:33 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=17837.14401.33 Donations & Support: http://www.houseoffusion.com/tiny.cfm/54 |
|
|
Re: Applying JS to dynamically created varsHere is the code I ended up with
function restoreDefaultValues(obj) { var getOriginalValue = parseInt(obj.name.substr(7, 2)); if (obj.options[ obj.selectedIndex ].value != '') { for (var i = 1; i<5; i++) { var makeObj = 'Company' + eval(getOriginalValue + i); document.getElementById( makeObj ).selectedIndex = 1; } } } Any ideas on how to calculate dynamic form fields? >You just loop over the form elements. In other words, use the form's number >of elements as your index and then use logic to determine what type of >element it is. Then you just validate them accordingly. Here is an example >using radio elements: > > ><script> >function checkform(obj_input) { > var checked = 0; > for (var i=0; i<obj_input.length; i++) { > if(obj_input.elements[i].type == 'radio') { > if(obj_input.elements[i].checked == true) { > checked++; > break; > } > } > } > if (checked == 0) { > alert("you did not check a radio button"); > return false; > } > return true; >} ></script> > > > ><form action="" method="post" onsubmit="return checkform(this)" >name="theform"> ><input type="radio" name="arad" value="true"><input type="radio" >name="arad"value="false"><br /> ><input type="text" name="atest" size="10"><br /> ><input type="submit" value="submit"> ></form> > > > >Warmest Regards, > >Phillip B. Holmes >http://phillipholmes.com >214-995-6175 (cell) > > > > > >-----Original Message----- >From: Torrent Girl [mailto:torrentgirl@...] >Sent: Wednesday, June 14, 2006 8:35 PM >To: Javascript >Subject: Applying JS to dynamically created vars > >Hello > >I need help with an issue. > >I am creating dynamically generated form fields so there can be 10 or 20 or >30 and so on (in groups of 10, and up to 50) > >I need to apply javascript validation to those fields. > >My question is how can I predict the number of fields there will be? > >I need to do things such as this: > >If field1 = "Null", Set field2, 3, 4, 5 to "NULL" > > >Thank you in advance for your help and I have a AM deadline ;) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Message: http://www.houseoffusion.com/lists.cfm/link=i:33:2878 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/33 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:33 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=17837.14401.33 Donations & Support: http://www.houseoffusion.com/tiny.cfm/54 |
| Free Forum Powered by Nabble | Forum Help |