Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to set an empty value of an input radio button element? 2

Status
Not open for further replies.

apostolchopov

Programmer
Joined
Jun 8, 2004
Messages
53
Location
BG
Hi, fellows!

How to set an empty value of an input radio button element by clicking on a button on the same Web-page?

Thanks in advance!
 
Without having any idea if it will work...

I would dynamically create and attach a new checkbox with the same name to your form, set it's checked property to be 'checked'... and then remove it from the form again.

Cheers,
Jeff

[tt]Jeff's Page @ Code Couch
[/tt]

What is Javascript? FAQ216-6094
 
>How to set an empty value of an input radio button element by clicking on a button on the same Web-page?

Radio button value is read-write. So what is behind the question? A demo.
[tt]
<html>
<head>
<script language="javascript">
function doit(srbtnname) {
var celem=document.getElementsByName(srbtnname);
for (var i=0;i<celem.length;i++) {
alert("before: "+celem.value);
}
var icount=0;
for (var i=0;i<celem.length;i++) {
celem.value=(celem.value=="")?"radio-"+icount:"";
icount++;
}
for (var i=0;i<celem.length;i++) {
alert("after: "+celem.value);
}
}
</script>
</head>
<body>
<form>
<input type="radio" name="rbtnname" value="radio-0">radio-0</input><br />
<input type="radio" name="rbtnname" value="radio-1">radio-1</input><br />
<input type="radio" name="rbtnname" value="radio-2">radio-2</input><br />
<input type="button" onclick="doit('rbtnname')" value="toggle radio value" /><br />
</form>
</body>
</html>
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top