How do I get the value of a radio button during fo

Results 1 to 2 of 2

Thread: How do I get the value of a radio button during fo

  1. #1
    Anuj Seth <anuj@sasi Guest

    Default How do I get the value of a radio button during fo

    Hi,<BR><BR>I need to validate a form before I allow the user to submit it. The form has a group of radio buttons. Let&#039s say it has two radio buttons called "YES" and "NO". The user has to select one of them. During the client-side form validation process, I could not figure out the method of getting the value of the selected radio button. I am using JavaScript to carry out form validation.<BR><BR>To validate the entries of a text box, I use the document.formname.textbox.value method to obtain the value of the text box. I tried the similar thing for a radio button, but I did not get the value.<BR><BR>Could someone shed some light on this!<BR><BR>Also, Is there a comprehensive tutorial available on Javascript somewhere on the net?<BR><BR>Thanks,<BR><BR>With Regards,<BR>Anuj<BR>

  2. #2
    MikeD Guest

    Default RE: How do I get the value of a radio button durin

    I think this is what you are looking to do. I found a sample very similar to what you were looking for at MSDN in the web workshop. In there they have a section for DHTML, HTML, and CSS that has a subsection of Forms.<BR> <BR>&#060;html&#062;<BR>&#060;head&#062;<BR>&#060; title&#062;Test Option Buttons&#060;/title&#062;<BR>&#060;script language="JavaScript"&#062;<BR>function validate(){<BR> //loop throught the collection of radSample<BR> for(i=0 ; i &#060; frmTest.radSample.length; i++){<BR> // if the radio is checked then alert the user of its value<BR> if(frmTest.radSample[i].checked){<BR> alert(i + " is = " + frmTest.radSample[i].value);<BR> return true;<BR> }<BR> }<BR>}<BR>&#060;/script&#062;<BR>&#060;/head&#062;<BR>&#060;body&#062;<BR>&#060;form name="frmTest" onsubmit="validate()"&#062;<BR> &#060;input type="radio" name="radSample" value="Yes"&#062;Yes<BR><BR> &#060;input type="radio" name="radSample" value="No"&#062;No<BR><BR> &#060;input type="submit" value="test"&#062;<BR>&#060;/form&#062;<BR> <BR>&#060;/body&#062;<BR><BR>&#060;/html&#062;<BR><BR>For a tutorial try - I have not used it but they generally have good content:<BR><BR>Another good reference is Microsofts scripting web site:

Posting Permissions

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