#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Posts
    41
    Rep Power
    12

    HTML button passing events to javascript


    Hi, this might be a very simple question, but I cant seem to find the answer. I have a form that has a number of submit buttons. I want to set it up so that the javascript only works when a certain button is pressed.

    ie pseudo code

    JavaScipt
    if (HTMLbuttonOne ==clicked)
    {
    validate form();
    }
    else if (HTMLbuttonTwo ==clicked)
    {
    do nothing;
    }

    Cheers.
  2. #2
  3. mod_dev_shed
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2002
    Location
    Atlanta, GA
    Posts
    14,817
    Rep Power
    1099
    Change the type to button and explicitly call the javascript for each button.
    Code:
    <input type="button" value="Validate / Submit" onclick="javascript:validateForm();" />
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Posts
    41
    Rep Power
    12
    Originally posted by jharnois
    Change the type to button and explicitly call the javascript for each button.
    Code:
    <input type="button" value="Validate / Submit" onclick="javascript:validateForm();" />
    No, I wanted the form to be validated and submited if they click one button, and not validated and submited if they click another button. The above only validates the form, so I would have to include another submit button. Which means that they will just submit without validateing. Users need to be forced to validate.
  6. #4
  7. mod_dev_shed
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2002
    Location
    Atlanta, GA
    Posts
    14,817
    Rep Power
    1099
    In the validateForm function, after you've done the validation and if everything is okay, add
    Code:
    document.myForm.submit();
  8. #5
  9. No Profile Picture
    Senior Citizen
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2001
    Location
    leftcoast
    Posts
    2,019
    Rep Power
    16
    <input type="submit" value="Validate & Submit" onclick="return validate form()">
    <input type="submit" value="Submit">
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Posts
    41
    Rep Power
    12
    Gracias amgios. Todo bien ahora.

IMN logo majestic logo threadwatch logo seochat tools logo