onClick trigger possible with checkbox?

Discussion in 'HTML & Website Design' started by cfnewb, Jun 26, 2007.

  1. #1
    Hi everyone, I am a new CF/HTML/JS learner. I am in the IT field but would like to expand my skill by doing something new so I thought I sign up for web development.

    I have a coworker who is very helpful and very knowledable in web all together. But I think I have asked him too much and would like to try a different avenue for help as I am learning. Plus, my coworker is on vacation so I have no one to bother about these questions :D

    I am looking to find out if it is possible to place an onClick on a checkbox? What I mean by this is before submiting the page, as soon as the user click on a checkbox, run the onClick event. Is that possible? If so, how?

    Thanks,
    cfnewb:confused:
     
    cfnewb, Jun 26, 2007 IP
  2. rgchris

    rgchris Peon

    Messages:
    187
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    <form method = "post" action = "http://www.example.com">
    <input type = "checkbox" onclick = "alert('I am now selected!');">
    <input type = "submit" value = "Submit">
    </form>
    Code (markup):
    Is something like that what you're looking for?
     
    rgchris, Jun 26, 2007 IP
  3. cfnewb

    cfnewb Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    rgchris, not exactly what I am looking for but thank you. So it is possible to place an onClick on a checkbox.

    Instead of the alert, I want to call a JS function.

    Here is a section of what I had coded for the two JS function (lots of missing code in between ofcourse):

    function verifyCheckbox3(form) {
    if (form.q4a[3].checked) {
    form.q4a[0].checked=false;
    form.q4a[1].checked=false;
    form.q4a[2].checked=false;
    return true;
    }
    }
    function verifyCheckbox2(form) {
    if (form.q4a[2].checked) {
    form.q4a[0].checked=false;
    form.q4a[1].checked=false;
    form.q4a[3].checked=false;
    return true;
    }
    }


    here is the checkbox section:

    <table>
    <tr>
    <td align=left><input type=checkbox name=q4a value=zero></td>
    <td><font size=2 face="Arial, Helvetica">checkbox zero</font></td>
    </tr>
    <tr>
    <td align=left><input type=checkbox name=q4a value=one></td>
    <td><font size=2 face="Arial, Helvetica">checkbox one</font></td>
    </tr>
    <tr>
    <td align=left><input type=checkbox name=q4a value=two></td>
    <td><font size=2 face="Arial, Helvetica">checkbox two</font></td>
    </tr>
    <tr>
    <td align=left><input type=checkbox name=q4a value=three></td>
    <td><font size=2 face="Arial, Helvetica">checkbox three</font></td>
    </tr>
    </table>


    How do I tie an onClick event on the checkbox to the JS function?
     
    cfnewb, Jun 26, 2007 IP
  4. veckd

    veckd Peon

    Messages:
    1,065
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #4
    sure it would be just like this:
    <input type="checkbox" name="q4a" value="two" onClick="yourfunction(your, parameters);" />
    Code (markup):
     
    veckd, Jun 26, 2007 IP
  5. cfnewb

    cfnewb Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    thanks! I think that is what I was looking for.
     
    cfnewb, Jun 26, 2007 IP
  6. veckd

    veckd Peon

    Messages:
    1,065
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #6
    No problem :)
     
    veckd, Jun 26, 2007 IP
  7. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #7
    Though instead of onClick, you might be more interested in onChange.
     
    deathshadow, Jun 26, 2007 IP
  8. cfnewb

    cfnewb Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    ah, I will look into this as well and see what works best. At my peon level, I am very happy that the possibility is there and that I found this forum. Thanks.
     
    cfnewb, Jun 26, 2007 IP