|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi,
I have a series of questions and each question has 3 checkboxes for a user to choose from. How do i go about making sure that only 1 checkbox is ticked and not 2 or 3 for each question? Before you go on and suggest that radio buttons are the way to go, i do know this but the company is called tickboxer and so a requirement is all selection boxes on the website need to be checkboxes. Does anyone have any JavaScript code that's compatible with ASP that will do the above? Any help would be greatly appreciated. |
|
#2
|
||||
|
||||
|
how about disabling the other check boxes when one is selected ?
__________________
“Life may not be the party we hoped for, but while we are here we should sing, dance and be merry all the time....... "
|
|
#3
|
||||
|
||||
|
This script seems to do what you need:
Code:
<html>
<head>
<title>Checkbox Groups Act As Radio Buttons</title>
</head>
<body>
<form name='f1' action='#'>
<p>
<input type=checkbox name='cb1'>
<input type=checkbox name='cb1'>
<input type=checkbox name='cb1'>
<input type=checkbox name='cb1'>
<p>--------------
<p>
<input type=checkbox name='cb2'>
<input type=checkbox name='cb2'>
<input type=checkbox name='cb2'>
<input type=checkbox name='cb2'>
</form>
<script type='text/javascript'>
function Cb2Rb( setRef )
{
this.boxGroup = setRef;
for( var i=0, len=setRef.length; i<len; i++ )
setRef[ i ].onclick=( function(inst, idx){return function(){inst.scan(idx)}} )(this, i);
this.scan=function(index)
{
if( this.boxGroup[ index ].checked )
for(var i=0, g=this.boxGroup, len=g.length; i<len; i++)
if( i != index )
g[i].checked = false;
}
/*28432953637269707465726C61746976652E636F6D*/
}
new Cb2Rb( document.forms.f1.cb1 );
new Cb2Rb( document.forms.f1.cb2 );
</script>
</body>
</html>
full discussion |
![]() |
| Viewing: ASP Free Forums > Programming > HTML, JavaScript And CSS Help > JavaScript - Code which ensure only one checkbox is checked at any given time |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|