Register  |  Login




Advertisement

Start Your Own Q&A Site

Create your own Q&A site easily, allowing you to quickly grow a new community around any subject matter or generate new organic traffic for your existing website.

Question

Status: Open Points: 75 Time: 10:25 - May 04, 2009  

claudio363

single radio button validation

hi, i have a problem with radio button.
i generate dinamically my radio button and if i have only one radio button i can't use the radio button length because it's undefined.
Can i do for validate it?

Categories

Answer Discussion
Tutorials

 

teddyjas

Date:: May 05, 2009

Time:: 08:51

what do you want to validate it?
Do you mean you want to validate the value?

Muhammad Amman

Date:: May 06, 2009

Time:: 12:03

claudio in this way u validate the button of radio look simple program:
</html>
</head>
<script type="text/javascript">
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>
</head>
<body>
<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>


</body>
</html>

claudio363

Date:: May 11, 2009

Time:: 04:04

Hi, i buyild dinamically my radio button and when there is only one of this this javascript don't function.


I post my solution for this ptoblem :

function isOneCheked(objForm){

for(jj=0; jj<= objForm.check_user.length; jj++)
{
if(objForm.check_user[jj].checked)
{
break;
return true;
}
}
return false;
}

function sigleRadioValue(objForm){
if(objForm.check_user.checked){
return true;
}else{
return false;
}
}

function validateChekSelection(objForm){
if(!isOneCheked(objForm))
{
if(!sigleRadioValue(objForm)){
window.alert("Selezionare almeno un utente");
return ;
}else{
objForm.submit();
}
}else
{
objForm.submit();
}
}

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?

Tutorials cannot be submitted until the Answer Discussion is complete.

Submit answers in the Answer Discussion area

Ask a Question

Have a new question? Ask!

You have 100 characters to use



Top Experts

View More

Rank

Expert

Points

1.

nidhi

10279

2.

oracleofDelphi

6493

3.

rcastagna

5596

4.

LAGM

4848

5.

PeterNZ

3487

6.

gonzalo

2840

7.

Mason

2770

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