Click to See Complete Forum and Search --> : Checkbox Script


Pratibha
03-06-2003, 09:08 AM
Hi All,

I put the following in my .jsp file

<tr><td><b>*Restart WebServer</b>
<input type=checkbox name="serverN" value="activated" checked>No
<input type=checkbox name="serverY">Yes<P></td>
</tr>

-----------------------------------------------
So now my question is:

By default I checked my checkbox as "No"

I need to do like if I check one box othershould be unchecked automatically.Like by default checked "serverN" then again I should not be able to check the "serverY" checkbox.Only either of them should be able to check.I hope this can be done thru javascript.

Can anyone assist me!

Thanks in advance!
Pratibha Marisetti
(Systems Administrator)

khalidali63
03-06-2003, 10:12 AM
Here is a solution to your problem


<script type="text/javascript">
function process(obj){
var frm = document.form1;
if(obj.name=="serverN"){
obj.checked = true;
frm.serverY.checked = false;
}else if(obj.name=="serverY"){
obj.checked = true;
frm.serverN.checked = false;
}
}
</script>
</head>

<body>
<form name="form1" action="">
<tr><td><b>*Restart WebServer</b><br>
<input type="checkbox" name="serverN" onclick="process(this);" checked="checked" >No
<input type="checkbox" name="serverY" onclick="process(this);">Yes<P></td>
</tr>
</form>



Cheers

Khalid

Pratibha
03-06-2003, 10:23 AM
Thanks Khalid!ITS working perfect..I like it.

Thank you very much...

Thanks,
Pratibha Marisetti
(Systems Administrator)

khayman2001
03-06-2003, 01:53 PM
You could also do it so much more simply by using a radio button instead of a checkbox.

:)

Pratibha
03-06-2003, 02:04 PM
Dan!I know but my supervisor didn't like that.

Thanks,
Pratibha Marisetti
(Systems Administrator)