Radio Button List server control and java script

  • Thread starter Thread starter jayuya
  • Start date Start date
J

jayuya

How can i check in java script if a asp.net radio button
list server control is selected?

I have some custom javascript function in the client side
that needs to run but I don't see the way to see if user
selected or not one of the options....

thanks,
jayuya
 
The aspx control obviously renders as normal HTML. Use
the ID/Name of the html control as usual.

An easy way to get the HTML name:
htmlName=replace(RadioButtonControl.UniqueName,":","_")
 
Hi

Example ( Should work... I did not check :) )

Replace FORMNAME/RADIONAME with yours
<html>
<head>
<script language="JavaScript">
function checkRadio(){
var bIsChecked = false;
var r = document.forms["myForm"].r1;
for(i=0;i<r.length;i++)
{
if( r.checked )
{
bIsChecked = true;
break;
}
}
if(!bIsChecked ) alert("Please check.... ");
return bIsChecked;
}
</script>
</head>
<body>
<form name="myForm">
<input type="radio" name="r1">
<input type="radio" name="r1">
<input type="radio" name="r1">
<input type="radio" name="r1">
<input type="radio" name="r1">
<input type="submit" onclick="return checkRadio()" value="Click to test
radio">
</form>
</body>
</html>

Note if for some reason the list has only 1 item the length will be
undefined.

And also we have a good group for client issues
microsoft.public.scripting.jscript

--
Best Regards
Vidar Petursson
==============================
Microsoft Internet Client & Controls MVP
==============================
 
Back
Top