get names of buttons

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

    get names of buttons

    Hello.

    I am new to Javascript and JSP. I would like to have multiple submit
    buttons in a form. Each button has a different action? How can I go
    about doing that? How can I obtain the button's name or id?

    Thank you
  • GArlington

    #2
    Re: get names of buttons

    On Apr 11, 9:35 am, Husain <husran...@gmai l.comwrote:
    Hello.
    >
    I am new to Javascript and JSP. I would like to have multiple submit
    buttons in a form. Each button has a different action? How can I go
    about doing that? How can I obtain the button's name or id?
    >
    Thank you
    <input type="button" name="???" onclick="alert( this.name)" .../>

    Comment

    • SAM

      #3
      Re: get names of buttons

      Husain a écrit :
      Hello.
      >
      I am new to Javascript and JSP. I would like to have multiple submit
      buttons in a form. Each button has a different action? How can I go
      about doing that? How can I obtain the button's name or id?
      Usual way of doing :

      - All submit-buttons have same name
      - each button has its own value according to some action
      - code server-side uses the name of submit button to know
      what action to serve (the submit-button's value)
      with the other elements of the form
      - javascript uses :
      1) an onclick attributed to the button
      - most simple :
      to give the value of button to a global variable
      <input type=submit value="Do That" name="send"
      onclick="ToDo=t his.value">
      - or a function to do somethin with the elements of the form
      2) the attribute 'onsubmit' given to the tag 'form'


      That can give :

      <html>
      <script type="text/javascript">
      var ToDo = '';
      function validate () {
      return confirm('Ok for this action : '+ToDo+' ?');
      }
      </script>
      <form action="javascr ipt:alert('mess age sent')"
      onsubmit="retur n validate();">
      <p><input type=submit name="send" value="First action"
      onclick="ToDo=t his.value">
      <p><input type=submit name="send" value="Second action"
      onclick="ToDo=t his.value">
      <p><input type=submit name="send" value="Third action"
      onclick="ToDo=t his.value">
      </form>
      </html>

      --
      sm

      Comment

      • Thomas 'PointedEars' Lahn

        #4
        Re: get names of buttons

        Husain wrote:
        I am new to Javascript and JSP. I would like to have multiple submit
        buttons in a form. Each button has a different action?
        No, that is not possible. You need to have different forms for different
        form actions. However, the server-side resource to receive the form data
        as referred to by one form element's `action' attribute can differentiate
        between the action to be performed according to the used submit button.
        How can I go about doing that? How can I obtain the button's name or id?
        Only the activated submit button is included in the list of successful
        controls. So you could use the same name and evaluate the different value
        server-side. However, it becomes more difficult with automated i18n.

        Another approach is to use a different control name for each submit button.
        Since only the activated submit button is considered a successful one, you
        only get its name in the request and not the names of the other buttons.

        This has nothing to do with "Javascript ", nor should client-side scripting
        be used to resolve it (unless further client-side actions are necessary on
        submit.)

        BTW, JSP is JavaServer Pages (not JavaScript Pages), which is therefore
        off-topic here and on-topic in comp.lang.java. *. Java != JavaScript.


        PointedEars
        --
        var bugRiddenCrashP ronePieceOfJunk = (
        navigator.userA gent.indexOf('M SIE 5') != -1
        && navigator.userA gent.indexOf('M ac') != -1
        ) // Plone, register_functi on.js:16

        Comment

        • Husain

          #5
          Re: get names of buttons

          On Apr 14, 7:19 am, Thomas 'PointedEars' Lahn <PointedE...@we b.de>
          wrote:
          Husain wrote:
          I am new to Javascript and JSP. I would like to have multiple submit
          buttons in a form. Each button has a different action?
          >
          No, that is not possible. You need to have different forms for different
          form actions. However, the server-side resource to receive the form data
          as referred to by one form element's `action' attribute can differentiate
          between the action to be performed according to the used submit button.
          >
          How can I go about doing that? How can I obtain the button's name or id?
          >
          Only the activated submit button is included in the list of successful
          controls. So you could use the same name and evaluate the different value
          server-side. However, it becomes more difficult with automated i18n.
          >
          Another approach is to use a different control name for each submit button.
          Since only the activated submit button is considered a successful one, you
          only get its name in the request and not the names of the other buttons.
          >
          This has nothing to do with "Javascript ", nor should client-side scripting
          be used to resolve it (unless further client-side actions are necessary on
          submit.)
          >
          BTW, JSP is JavaServer Pages (not JavaScript Pages), which is therefore
          off-topic here and on-topic in comp.lang.java. *. Java != JavaScript.
          >
          PointedEars
          --
          var bugRiddenCrashP ronePieceOfJunk = (
          navigator.userA gent.indexOf('M SIE 5') != -1
          && navigator.userA gent.indexOf('M ac') != -1
          ) // Plone, register_functi on.js:16
          Thank you all for your kind response.

          Comment

          Working...