Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-30-2006, 03:57 AM   PM User | #1
eranwein
New Coder

 
Join Date: Jan 2006
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
eranwein is an unknown quantity at this point
checkBox issue

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>
eranwein is offline   Reply With Quote
Old 01-30-2006, 04:54 AM   PM User | #2
shyam
Senior Coder

 
shyam's Avatar
 
Join Date: Jul 2005
Posts: 1,563
Thanks: 2
Thanked 163 Times in 160 Posts
shyam will become famous soon enough
its as simple as
Code:
frm['checkbox1'].click();
shyam is offline   Reply With Quote
Old 01-30-2006, 05:00 AM   PM User | #3
glenngv
Supreme Master coder!


 
glenngv's Avatar
 
Join Date: Jun 2002
Location: Los Angeles, CA Original Location: Philippines
Posts: 10,241
Thanks: 0
Thanked 112 Times in 111 Posts
glenngv will become famous soon enough
Code:
<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 for that call to work)
__________________
Glenn
_____________________________________________
Play Tower of Hanoi Android app (Ad-FREE!)
Play Tower of Hanoi Android app (FREE!)
Go to Tower of Hanoi Leaderboard
Play Tower of Hanoi Facebook app
glenngv is offline   Reply With Quote
Old 01-30-2006, 05:03 AM   PM User | #4
eranwein
New Coder

 
Join Date: Jan 2006
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
eranwein is an unknown quantity at this point
thanks. i figured that it's simple.
eranwein is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:46 AM.


Advertisement
Log in to turn off these ads.