multiple buttons on a form

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Matt

    multiple buttons on a form

    The ASP page has multiple buttons, and when the user clicks different
    buttons, it will submit the form data to different URLs.

    My first approach was to use BUTTON type, and triggers javascript function
    to submit the form data. However, it didn't work properly and I changed to
    use SUBMIT type.

    <INPUT TYPE="BUTTON" NAME="action1" VALUE="Return to Main Search Page"
    onClick="action 1()">

    function action1()
    { //etc...
    document.myform .action = "main.asp"
    document.myform .submit();
    }

    OR

    <INPUT TYPE="SUBMIT" NAME="action1" VALUE="Return to Main Search Page"
    onClick="action 1()">

    function action1()
    { //etc...
    document.myform .action = "main.asp"
    }

    So which is the appropriate way? please advise. thanks!!
  • Evertjan.

    #2
    Re: multiple buttons on a form

    Matt wrote on 06 jul 2004 in comp.lang.javas cript:
    [color=blue]
    > The ASP page has multiple buttons, and when the user clicks different
    > buttons, it will submit the form data to different URLs.[/color]
    [color=blue]
    > My first approach was to use BUTTON type, and triggers javascript
    > function to submit the form data. However, it didn't work properly and
    > I changed to use SUBMIT type.
    >
    > <INPUT TYPE="BUTTON" NAME="action1" VALUE="Return to Main Search Page"
    > onClick="action 1()">
    >
    > function action1()
    > { //etc...
    > document.myform .action = "main.asp"
    > document.myform .submit();
    >}
    >
    > OR
    >
    > <INPUT TYPE="SUBMIT" NAME="action1" VALUE="Return to Main Search Page"
    > onClick="action 1()">
    >
    > function action1()
    > { //etc...
    > document.myform .action = "main.asp"
    >}
    >
    > So which is the appropriate way? please advise. thanks!![/color]

    There is no "appropriat e way".
    In programming you can have your personal preference.

    If you use the submit-button then I would use

    <form action="main.as p" method="post">
    <input type="submit" name="actions" value="action1" >
    <input type="submit" name="actions" value="action2" >

    and have serverside ASP[vbs] find out what action you want to accomplish:

    if request.form("a ctions")="actio n2" then response.redire ct "act2.asp"

    ==============

    but clientside coding is possible [to prohibit submission, par example]:

    <form onsubmit="retur n myAction()" action="main.as p" method="post">
    <input type="submit" name="actions" value="action1" onclick="a=1">
    <input type="submit" name="actions" value="action2" onclick="a=2">
    <input type="submit" name="actions" value="action3" onclick="a=3">

    where, when action() returns false, the submit will not be carried out:

    function myAction()
    // no submit if a=1
    return (a!=1)
    }

    not tested



    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)

    Comment

    • Brian

      #3
      Re: multiple buttons on a form

      Matt wrote:[color=blue]
      > The ASP page has multiple buttons, and when the user clicks
      > different buttons, it will submit the form data to different URLs.
      >
      > My first approach was to use BUTTON type, and triggers javascript
      > function to submit the form data.[/color]

      This is a fragile solution; where js is not available, does the form
      do anything? This is generally best done server side.
      [color=blue]
      > it didn't work properly and I changed to use SUBMIT type.
      >
      > <INPUT TYPE="BUTTON" NAME="action1" VALUE="Return to Main Search
      > Page" onClick="action 1()">
      >
      > OR
      >
      > <INPUT TYPE="SUBMIT" NAME="action1" VALUE="Return to Main Search
      > Page" onClick="action 1()">[/color]
      [color=blue]
      > So which is the appropriate way?[/color]

      Since the button that does not do anything, I'd choose input
      type="button", which has no default behavior. It looks like the form
      just gives someone a new page, so a simple text link is probably best.
      But if the form does something else, how about this?:

      <INPUT TYPE="SUBMIT" NAME="action1"
      VALUE="Return to Main Search Page" onClick="action 1()">

      Then use javascript to change the behavior, e.g., return false
      onSubmit and do something else. That makes it transparent to the user.

      --
      Brian (remove ".invalid" to email me)

      Comment

      Working...