Select Categories Below
Status: Closed Points: 75 Time: 17:54 - Dec 08, 2008
san
I am using this function to validate my form.....I am able to validate all the fields except radio buttons, I am not able to figure it out whats the problem with the function. how do i make it so that it validates the radio buttons too here is the code..... <script type="text/javascript"> var strAlertMsg = "" var focusField = "" //Validate Radio Button function checkRadioControl(theForm,strFieldName,strMsg){ var objFormField = theForm.elements[strFieldName] intControlLength = objFormField.length bolSelected = false; for (i=0;i<intControlLength;i++){ if(objFormField[i].checked){ bolSelected = true; break; } } if(! bolSelected){ strAlertMsg += "- "+ strMsg +" is Required.\n"; return false; } return true; } //Begin Page Validation function validateForm(theForm){ strAlertMsg = "" focusField = "" checkRadioControl(theForm,'radio1','What Kind of Issue do you have') if(strAlertMsg !=""){ alert("Please correct the following errors:\n____________________________\n\n" + strAlertMsg); eval("theForm." + focusField + ".focus()"); return false; } return true; } </script> <form id="form1" action="new5.asp" method="post" onsubmit="return validateForm(this);"> <tr> <td colspan="2"><div align="left"> <b><label id="lblRadio" for="radio1">What Kind of Issue do you have?:</label></b> <em>*</em> </div></td> </tr> <tr> <td><input type="radio" id="radio1" name="radio1" value="01" /> Problem/Question </td> <td><input type="radio" name="radio1" value="02" />Comment </td> </tr> </form> Thanks
Categories:
Add Categories
When adding more than one category, separate them with commas.
Advertisement
shashi.programmer
Date:: Dec 10, 2008
Time:: 00:58
<script language="javascript1.1"> function valbutton(thisform) { // place any other field validations that you require here // validate myradiobuttons myOption = -1; for (i=thisform.myradiobutton.length-1; i > -1; i--) { if (thisform.myradiobutton[i].checked) { myOption = i; i = -1; } } if (myOption == -1) { alert("You must select a radio button"); return false; } alert("You selected button number " + myOption + " which has a value of " + thisform.myradiobutton[myOption].value); // place any other field validations that you require here thisform.submit(); // this line submits the form after validation } </script> <form name="myform"> <input type="radio" value="1st value" name="myradiobutton" />1st<br /> <input type="radio" value="2nd value" name="myradiobutton" />2nd<br /> <input type="radio" value="3rd value" name="myradiobutton" />3rd<br /> <br /> <input type="submit" name="submitit" onclick="valbutton(myform);return false;" value="Validate" /> <input type="reset" name="reset" value="Clear" /> </form>
Question Answered
This question has been closed, and points have been rewarded to the following experts:
You're welcome however to comment or give additional information or if you wish, you have the ability to write a Tutorial in the Tutorial Area.
Answer this Question
New User
Email:
Upon submission of this form, you will automatically be registered as a Quomon user and we will send your login information to this address
Registered User
Username:
Password:
Forgot Your Password?
Enter your email address below and we will resend your login information to you.
Login Information Sent
Questions
Microsoft VB Script compilation error '800a03fa' - 'Expected Wend'
Need help with enabling/disabling only few text fields in the form
You have 100 characters to use
Rank
Expert
Points
1.
9829
2.
6493
3.
5596
4.
4773
5.
3487
6.
2765
7.
2520
8.
2303
9.
1820
10.
917
Register today to share your knowledge with the community and be recognized and rewarded for your contributions.
Register Here
"Psst, Quomon is a great site. Pass it on." Tell a Friend | Link To Us | Save to Delicious | Digg it
Language Options
English:
Español:
Sponsors
Questions and Answers Software Real Estate Postcards Marketing Fulfillment