Click to See Complete Forum and Search --> : properties


Xerces
08-21-2003, 04:57 PM
Is it possible to change properties with javascript.

Let me give an example (which happens to be the one I need ;) )

you have 4 radiobuttons, once one of them is clicked, there should be no more possibility to change the choice.

would something like document.getElemenetById[id].enabled = false;
work or is there another solution?

Exuro
08-21-2003, 05:16 PM
You're on the right track, but you're not quite there. First, getElementById is a method, not an [i]array[i]. This means that it is followed by parenthesis () not brackets []. Secondly, there is no "enabled" property, however, there is a "disabled" property. So if you just changed those two things your code should work ok. Here's an example of how you would use that:

<html>
<head>
<script type="text/javascript">
<!--
function disableRadios() {
for (i=1;i<=3;i++) {
document.getElementById('r'+i).disabled=true;
}
}
//-->
</script>
</head>
<body>
1<input type="radio" name="r" id="r1" value="1" onclick="disableRadios()" />
2<input type="radio" name="r" id="r2" value="2" onclick="disableRadios()" />
3<input type="radio" name="r" id="r3" value="3" onclick="disableRadios()" />
</body>
</html>

Xerces
08-21-2003, 05:18 PM
muchos gracias mi amigo :D