Validating a dynamic asp form with txt, sel, rad a

Results 1 to 2 of 2

Thread: Validating a dynamic asp form with txt, sel, rad a

  1. #1
    Join Date
    Dec 1969

    Default Validating a dynamic asp form with txt, sel, rad a

    Is there a tutorial or how-to on the ways to validate a form for the above types of fields when they are dynamically shown pbased on previous inputs. I have been searching and thinking how to use the basic validation where the form names are preceded by a key work like &#039;required&#039; but they only work for text and selects. Is there another basic validation script to solve the problem for radio and checkboxes?<BR><BR>Josh<BR>Thanks Josh

  2. #2
    Join Date
    Dec 1969

    Default What's your definition?

    I presume that validation of a group of radio buttons means that the user has to have pushed one (presumably, the group started off with all of them deselected?).<BR><BR>But what does it mean to validate a group of check boxes?<BR><BR> about if we allow you to specify the minimum and maximum number of selections allowed in the group?<BR><BR>Okay, so....<BR><BR>&#060;SCRIPT&#062;<BR>function checkGroup( grp, minChk, maxChk )<BR>{<BR>&nbsp; &nbsp; var count = 0<BR>&nbsp; &nbsp; for ( var i = 0; i &#060; grp.length; ++i )<BR>&nbsp; &nbsp; {<BR>&nbsp; &nbsp; &nbsp; &nbsp; if ( grp[i].checked ) ++count;<BR>&nbsp; &nbsp; }<BR>&nbsp; &nbsp; if ( count &#060; minChk )<BR>&nbsp; &nbsp; {<BR>&nbsp; &nbsp; &nbsp; &nbsp; alert("You must select at least " + minChk<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + " from the " + + " group.");<BR>&nbsp; &nbsp; &nbsp; &nbsp; return false;<BR>&nbsp; &nbsp; }<BR>&nbsp; &nbsp; if ( count &#062; maxChk )<BR>&nbsp; &nbsp; {<BR>&nbsp; &nbsp; &nbsp; &nbsp; alert("You must select no more than " + maxChk<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + " from the " + + " group.");<BR>&nbsp; &nbsp; &nbsp; &nbsp; return false;<BR>&nbsp; &nbsp; }<BR>&nbsp; &nbsp; // okay!<BR>&nbsp; &nbsp; return true;<BR>}<BR><BR>function formValidate( frm )<BR>{<BR>&nbsp; &nbsp; return chkGroup( frm.RadioGroup, 1, 1 )<BR>&nbsp; &nbsp; &nbsp; &nbsp; && chkGroup( frm.CheckGroup, 2, 4 );<BR>}<BR>&#060;/SCRIPT&#062;<BR><BR>&#060;FORM ... onSubmit="return formValidate(this);"&#062;<BR>...<BR>Select one:<BR>&#060;INPUT Type=Radio Name="RadioGroup" Value=1&#062; 1<BR>&#060;INPUT Type=Radio Name="RadioGroup" Value=2&#062; 2<BR>&#060;INPUT Type=Radio Name="RadioGroup" Value=3&#062; 3<BR>&#060;INPUT Type=Radio Name="RadioGroup" Value=4&#062; 4<BR>...<BR>Select at least 2 but no more than 4:<BR>&#060;INPUT Type=Checkbox Name="CheckGroup" Value="A"&#062; Apples<BR>&#060;INPUT Type=Checkbox Name="CheckGroup" Value="B"&#062; Bananas<BR>&#060;INPUT Type=Checkbox Name="CheckGroup" Value="C"&#062; Cherries<BR>&#060;INPUT Type=Checkbox Name="CheckGroup" Value="D"&#062; Dates<BR>&#060;INPUT Type=Checkbox Name="CheckGroup" Value="E"&#062; Eggplant<BR>&#060;INPUT Type=Checkbox Name="CheckGroup" Value="F"&#062; Froot loops<BR>...<BR>&#060;/FORM&#062;<BR><BR>*************************<BR><BR >Isn&#039;t that neat? We got to use one function to check both types of form fields?<BR><BR>**** UNTESTED CODE **** let me know if there are errors.<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts