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

    Join Date
    May 2001
    Location
    Ottawa, Ontario
    Posts
    50
    Rep Power
    13

    Triggering particular submit button with JavaScript


    I have a form with two submit buttons:

    <form method="POST" action="myscript.cgi">
    many-many fields
    <input type="submit" name="task" value="t1">
    <input type="submit" name="task" value="t2">
    <form>

    So, when 't1' is clicked this request is produced
    http://www.mysite.com/myscript.cgi?m...ters&submit=t1

    Is there a way to load the same url from JavaScript function, so that it's the same as when a particular button is clicked? There are too many parameters to list them all and append the last one.
    This doesn't work:
    document.myform.task.value = "t1";
    document.myform.submit();

    Any ideas?
  2. #2
  3. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Location
    Sacramento, CA
    Posts
    1,710
    Rep Power
    14
    Well, I think your url should end with &task=t1, not &submit=t1. Also, as far as I know calling .submit() calls the first submit button in your form. You might put some sort of validation script that will change the value of submit.
    Something like:
    Code:
    function validate() {
       if ( change_submit_val_is_set ) {
          document.form.task.value = new_value;
       }
       return true;
    }
    Then set your change_submit_val_is_set variable before calling document.form.submit().
    There might be an easier way to do this, though.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2001
    Posts
    765
    Rep Power
    13
    Please explain more clearly what you want the result to be. You have two submit buttons, which appear identical to the user (slightly different legends). What's the difference between them?

    Invoking the submit() method doesn't call any 'buttons'.
    Last edited by mrrichardfeder; May 6th, 2002 at 06:50 PM.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2002
    Location
    Seattle WA
    Posts
    863
    Rep Power
    14
    Code:
    mySubmitButton.click()
    Should work. It should act as if the user clicked the particular button. Haven't tried it though.

    MSDN click() method

IMN logo majestic logo threadwatch logo seochat tools logo