Friday 26 September 2014

Select single check box in the presence of multiple checkbox

<input type="checkbox"  name="adsearchPolitical" id="adsearchPolitical" onClick="unselectCheckbox(this);"/>
Political<br />
<input type="checkbox" name="adsearchSocial" id="adsearchSocial" onClick="unselectCheckbox(this);"/>
Social<br />
<input type="checkbox" name="adsearchEconomy" id="adsearchEconomy" onClick="unselectCheckbox(this);"/>
Economy<br />

<script>
function unselectCheckbox(objct)
{
var obj = objct.checked;//saving initial value
document.getElementById("adsearchPolitical").checked=false;
document.getElementById("adsearchSocial").checked=false;
document.getElementById("adsearchEconomy").checked=false;
if(obj==false)
objct.checked=false;
else
objct.checked=true;
}
</script>


NOTE:
if we take var obj = ojbct ;
then if we change the value object object and try to access the previous value of obj then its value already change bcz here obj act as pointer to objct.
That’s y I use
obj=objct.checked;

now this time obj will contains simple value either true or false.

No comments:

Post a Comment