Javascript checkboxs
Is it possible to do a radio form option with checkboxs using javascript ?
0 yes 0 no <-- radio, with same name it's one or the other
_ _
|_| |_| <-- checkbox, any can be selected
What I have is two checkboxs but only want one to be checked, javascript isn't my strong point so am a bit lost.
I'm trying to do something like (php) if(checkbox1[123] == "selected"){ checkbox2[123] == "unselect"; }
I can't use radio form buttons unless there is a way to unselect one of them. a normal radio option once clicked is either/or, no unselect option.
Or even a conformation alert on selection of the second checkbox if first is selected warning it could short out the universe and on ok or cancel the second is unselected.
If only one is selected its fine, but not if both are.
druagord posted this at 00:23 — 15th July 2004.
He has: 335 posts
Joined: May 2003
<script language="Javascript">
function check_checkbox(intBox)
{
if(document.myform.chkoption1.checked && document.myform.chkoption2.checked)
{
if(intBox==1)
{
document.myform.chkoption2.checked=false;
}
else
{
document.myform.chkoption1.checked=false;
}
}
}
</script>
and in the page use
<form name="myform">
<input type="checkbox" name="chkoption1" onchange="check_checkbox(1)">
<input type="checkbox" name="chkoption2" onchange="check_checkbox(2)">
</form>
IF , ELSE , WHILE isn't that what life is all about
Busy posted this at 02:03 — 15th July 2004.
He has: 6,151 posts
Joined: May 2001
Saving my bacon again druagord
I can't change the 'name' in the input tag as it's a database generated array, can I use id or something instead?
Another problem is there can be from one to a thousand and one sets of checkbox sets
druagord posted this at 03:43 — 15th July 2004.
He has: 335 posts
Joined: May 2003
if you change the name just change it too in the script to add more checkbox youre id idea is a good one depending how it is set up you could loop trought all the id's with getelementbyid i won't write the code right now i would need my book for
that if nobody answered tomorow i'll give you something
IF , ELSE , WHILE isn't that what life is all about
druagord posted this at 03:58 — 15th July 2004.
He has: 335 posts
Joined: May 2003
by the way i just remembered i needed something like that once i used radio button and added a choice named none i my case it solved the problem
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.