How to Handle more than one submit button in single form?

Discussion in 'PHP' started by asparsh, Nov 15, 2009.

  1. #1
    Hi
    I have one PHP file which contains one Form. In this form there are two Submit type Buttons
    <input type="submit" name="edit" value="save">
    <input type="submit" name="cancel" value="cancel">
    <form name="myform" onsubmit="return validate()">

    My problem is : When i m trying to use Javascript onsubmit event of a form it confused due to two submit buttons and onsubmit of any button(save or cancel) it runs Javascript. Generally it should not run on cancel button.

    Please provide solution as soon as possible.

    thanks in advance.

    Anish Panchal
    www.tatvasoft.com
    www.sparsh-technologies.com
     
    asparsh, Nov 15, 2009 IP
  2. mastermunj

    mastermunj Well-Known Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #2
    what should happen on cancel?
    why not make cancel a normal button?
     
    mastermunj, Nov 15, 2009 IP
  3. asparsh

    asparsh Guest

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    On cancel ,redirect to another php page
     
    asparsh, Nov 16, 2009 IP
  4. chandan123

    chandan123 Prominent Member

    Messages:
    11,586
    Likes Received:
    578
    Best Answers:
    0
    Trophy Points:
    360
    #4
    why u need cancel button ? u can use type=reset instead :)
     
    chandan123, Nov 16, 2009 IP
  5. mastermunj

    mastermunj Well-Known Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #5
    then you can simply change action of the form and submit it OR use location.href
     
    mastermunj, Nov 16, 2009 IP
  6. b.krishna

    b.krishna Well-Known Member

    Messages:
    39
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    106
    #6
    Make the second button normal and write javscript redirection code on onclick event to redirect on another page. see example below.

    <input type="submit" name="edit" value="save">
    <input type="button" name="cancel" value="cancel" onclick="javascript:window.location='http://redirectedurl.com'">

    This should solve your issue.
     
    b.krishna, Nov 16, 2009 IP
  7. asparsh

    asparsh Guest

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Oh, It's working!
    thanks for the solution.

    Anish Panchal
    www.tatvasoft.com
    www.sparsh-technologies.com
     
    asparsh, Nov 16, 2009 IP