Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: checkBox issue

  1. #1
    New Coder
    Join Date
    Jan 2006
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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>

  • #2
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    its as simple as
    Code:
    frm['checkbox1'].click();

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,965
    Thanks
    0
    Thanked 236 Times in 233 Posts
    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)

  • #4
    New Coder
    Join Date
    Jan 2006
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks. i figured that it's simple.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •