Radio Button List server control and java script

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
 
D

David Waz...

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,":","_")
 
V

Vidar Petursson

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
==============================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top