Radio Button

Results 1 to 2 of 2

Thread: Radio Button

  1. #1
    Join Date
    Dec 1969

    Default Radio Button

    Hi, <BR><BR>I have ASP Page where i retrive users record from a table. and each record have a radio button. <BR><BR>If the user hits the submit button with out choosing the radio button to select one user he will recive a message to select one of the user by choosing one of the radio button.<BR><BR>this the code: <BR><BR>&#060;script language="JavaScript"&#062;<BR>&#060;!--<BR><BR>function Validate(frm, btnName)<BR>{<BR> var btn = frm[btnName]<BR> var valid<BR> <BR> for (var x = 0;x &#060; btn.length; x++)<BR> {<BR> valid = btn[x].checked<BR> if (valid) {break}<BR> <BR> }<BR> if(!valid)<BR> {<BR> alert("Please select an answer.")<BR> return (false);<BR> }<BR> <BR> document.form.action="Psign.asp";<BR> document.form.value = submit<BR> document.form.value();<BR> return (true);<BR>}<BR>--&#062;<BR>&#060;/script&#062;<BR>and its working fine when i retrive more than one record. the message is appearing when i don&#039;t choose any record and when i choose and hit submit i go to the other page. <BR><BR>But when i retrive only one record is not working. I got the message when i don&#039;t choose any record and when i choose the record and hit submit still the message appears and i don&#039;t move to other page. <BR><BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default Yep, well known problem...

    ...or, actually, it&#039;s not a problem at all. It&#039;s just the way the DOM of the browser is specified:<BR><BR>If you have more than one form field with the same name, then an array with that name is created. If you only have one field with a given name, then no array is created.<BR><BR> have to check to see if you have an array. That&#039;s all.<BR><BR>function Validate(frm, btnName)<BR>{<BR> var btn = frm.elements[btnName]; // should use .elements<BR> var valid = false;<BR><BR> if ( btn.length == null )<BR> {<BR> // not an array<BR> valid = btn.checked;<BR> } else {<BR> for (var x = 0;x &#060; btn.length; x++)<BR> {<BR> if ( btn[x].checked ) valid = true;<BR> // you could break, but why bother??<BR> }<BR> }<BR> ...<BR><BR>**********<BR> <BR> document.form.action="Psign.asp"; // okay<BR> document.form.value = submit; // WHAT???<BR> document.form.value(); // WHAT???<BR> return (true);<BR>}<BR><BR>Did you mean to code<BR> document.form.submit( );<BR>???<BR><BR>You could do that. But then there is no point in doing <BR> return true;<BR>because once you call submit(), the HTML page is gone bye-bye.<BR><BR>On top of that, though, why do you code<BR> document.form.xxxx<BR>when you are ALREADY passing in the reference to the form, as the variable frm???<BR><BR>At most, I would do:<BR> frm.action = "Psign.asp";<BR> return true;<BR>and nothing more. Assuming, that is, that the function is being called from the &#060;FORM&#062; tag via:<BR> <BR> &#060;FORM ... onSubmit="return Validate(this,&#039;theButtonName&#039;);" &#062;<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