Register  |  Login



Question

Status: Closed Points: 75 Time: 17:54 - Dec 08, 2008  

san

I need help regarding the validation of the form using javascript

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

Answer Discussion
Tutorials

 

Q&A System for Websites and Corporate Collaboration

Advertisement

  • Generates significant organic traffic for websites
  • Saves companies money, resources, and time

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 />&nbsp;<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:


shashi.programmer: 75

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?

No tutorials have been submitted yet. Want to be the first?

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?

Ask a Question

Have a new question? Ask!

You have 100 characters to use



Top Experts

View More

Rank

Expert

Points

1.

nidhi

9829

2.

oracleofDelphi

6493

3.

rcastagna

5596

4.

LAGM

4773

5.

PeterNZ

3487

6.

gonzalo

2765

7.

Mason

2520

8.

jgivoni

2303

9.

xarcus

1820

10.

Anpanman

917

Become an Expert

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! Digg it



Language Options

English:

www.quomon.com

Español:

www.quomon.es