House of Fusion
Search over 2,500 ColdFusion resources here
  
Home of the ColdFusion Community

Mailing Lists
Home /  Groups /  Javascript

Dynamic Form Field Validation

  << Previous Post |  RSS |  Sort Oldest First |  Sort Latest First |  Subscribe to this Group Next >> 
Hello All.
Torrent Girl
12/16/08 11:43 A
Firstly: <script language="javascript">
Peter Boughton
12/16/08 02:03 P
Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Torrent Girl
12/16/2008 11:43 AM

Hello All. I need a sample of a form that validates dymnically created form fields. Specifically checkboxes and text fields all in one form. On the form a user chooses a product by selecting a checkbox. I have the syntax for this and it is working propery. I need to add another function to make sure the users enters a quantity. Here is my script: <script language="javascript"> function checkForm() { var el = document.forms[0].elements; for(var i = 0 ; i < el.length ; ++i) { if(el[i].type == "checkbox") { var checkboxgroup = el[el[i].name]; var itemchecked = false; for(var j = 0 ; j < checkboxgroup.length ; ++j) { if(checkboxgroup[j].checked) { itemchecked = true; break; } } if(!itemchecked) { alert("Please select a product"); if(el[i].focus) el[i].focus(); return false; } } } return true; } } </script>

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Peter Boughton
12/16/2008 02:03 PM

Firstly: <script language="javascript"> The language attribute does *nothing* - it is a meaningless waste of space. If you want to identify a script as JS, use type="text/javascript" instead. Next: Use jQuery. It will make your existing JavaScript a billion times easier to work with, and make what you're trying to do now so much easier you'll wonder how you coped without it. As for making sure a user has entered a quantity... that existing code doesn't tell me anything about how your form is laid out, so there's no way to be sure what you need to do. Supply the HTML for the form, and I can have a go at giving a solution.


<< Previous Thread Today's Threads Next Thread >>

Search javascript

May 23, 2013

<<   <   Today   >   >>
Su Mo Tu We Th Fr Sa
       1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31   

Designer, Developer and mobile workflow conference