...

View Full Version : checkBox issue



eranwein
01-30-2006, 03:57 AM
i'm trying to simulate a click on a checkbox from an outside button.
in the code below the button marks the checkBox as "checked" but does'nt call the checkBox's onClick() function. i also tried onChange() but still it didnt work.
is there a way to do that?

function showCheckBoxValue(a)
{
alert(a.value);
}


function clickCheckBox()
{
frm = document.forms['form1'];
frm['checkbox1'].checked = true;
}

</script>

<form action="" method="post" name="form1">


<input type="hidden" name = "colors" value="1">
<input type="checkbox" name="checkbox1" value="5" onClick="showCheckBoxValue(this)">
<input type="button" name="a" onClick="clickCheckBox()">



</form>

shyam
01-30-2006, 04:54 AM
its as simple as

frm['checkbox1'].click();

glenngv
01-30-2006, 05:00 AM
<input type="button" name="a" onClick="this.form.checkbox1.click();" />
That will work in IE but not in other browsers (though other browsers may have additional code (http://www.codingforums.com/showthread.php?t=7495#post34595) for that call to work)

eranwein
01-30-2006, 05:03 AM
thanks. i figured that it's simple. :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum