SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Using multiple submits on form

    I thought I was somewhat a js veteran until a copy of Simply Javascript was put in front me. My first exposure to coding with js in that object/class based manner. So, assuming I want to implement interaction with the DOM object model as described in this book for a web app currently under development, in WAMP Php/Cake framework, no less ...

    Imagine I have a single input form with multiple submit buttons, all with same with value -- simply imagine 10 submit buttons on form, each labeled "Add". I need to intercept the submit, determine which submit button was used (assume unique IDs and Names assigned to each), and set hidden elements in response to that particular submit that the Cake controller acts upon.

    So, I know I have to use eventHandlers and eventListeners, interact with the DOM elements to set the hidden values, but just not a clear idea of how to bring all that together as described in that publication.

    Can anyone point me down a right/proper coding path to do this?

    TIA,

    Rick

  2. #2
    SitePoint Member
    Join Date
    May 2003
    Location
    Connecticut
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It sounds like you are making this more difficult than it needs to be.

    Why not just have onclick of those buttons set the hidden hidden input with name... lets say action. So you set the value of action to Add, Delete, or whatever based on the button that was clicked.

    This requires no real work and certainly is the easiest approach to take.

  3. #3
    SitePoint Zealot detzX's Avatar
    Join Date
    Oct 2006
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Or a form for each submit? You need to give more info but that's what I would do as long as there were not more elements that were shared amongst them all. If there were do what md_doc said.
    www.invoicejournal.com - Invoice clients for Free

  4. #4
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    input elements of type= 'submit' do not pass their name=value to the server, they just submit the form.

    Use inputs with type='button', value='Add' and no names.
    set an onclick handler for each button that assigns a name to that button and calls theform.submit() method

    Only elements with names are sent with the form, so the php script can examine the name that has a value of 'Add' and respond appropriately.

  5. #5
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the replies.

    The solutions you outlined are how I would have done it prior to those object-class based methods described in the aforementioned publication, which portrays keeping html and javascript completely separate from one another -- that means no usage on the on-click event within the input definition. I do agree it does make it harder for up-front creation on the surface, particularly when you haven't yet learned to write javascript in such a manner. I was just curious how to go about a basic task like this without such intermixing. Oh well, I'll get there eventually.

    Rick

  6. #6
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There is no reason to set an event handler in the html code of your elements.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •