PDA

View Full Version : html option buttons


nvrs_prasad
10-08-2004, 12:50 AM
Hi

In a html page I have two radio buttons

<input checked type=radio name=name1>
<input type=radio name=name1>

But In one case I don't want the user to change the default values and I don't want disable the radio buttons. How todo that one? How to write javascript function

thanks in advance

Goldilocks
10-08-2004, 02:43 AM
You can call the following function everytime someone clicks on any of the radio buttons. I originally used this bit of code with asp so the bit hilighted in red should be changed for the original value of the radio button (which I presume is 1).


<script language="javascript">
//Locks radio buttons so they can't be edited
function resetVal() {
var ansvar = <%=ansvar%>

for (i=0; i<2; i++) {
if ((i+1)==ansvar) {
document.form1.radiobutton[i].checked=true
}
else {
document.form1.radiobutton[i].checked=false
}
}
}
</script>


Here is the radio button code:


<input type=radio name="name1" value="1" checked onclick="resetVal()">
<input type=radio name="name1" value="2" onclick="resetVal()">