How to use multiple button in single php form with validation?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nawedita
    New Member
    • Mar 2010
    • 6

    #1

    How to use multiple button in single php form with validation?

    Hello everyone..


    I am trying to use multiple buttons in single php form with validations with given below functions:
    But i am facing problem when i click on submit button after checking all validations,its not submitted.

    Code:
    <input type="button" name="button" value="Submit" onClick="return submit_form();buttonClicked(1);">
    <input type="button" name="button" id="button" value="Preview" onClick="buttonClicked(2)">
    <input type="button" name="button" id="button" value="Print" onClick="buttonClicked(3)">
    
    <script type="text/javascript">
    function buttonClicked(which){
    if (which == 1 ) {   
    document.f1.action = 'ebooking_email.php';
    }
      else if(which==2) { 
          document.f1.target="_blank";
             document.f1.action = 'preview_booking.php'
        }
    	 else if(which==3) { 
            document.f1.target="_blank";
             document.f1.action = 'ebooking_print.php'
        }
         document.f1.submit(); 
    }
    </script>
  • dlite922
    Recognized Expert Top Contributor
    • Dec 2007
    • 1586

    #2
    put alert() calls in each of your if functions to see if any of them get called.

    I don't think there's such a thing as document.f1

    This is a Javascript issue and not a PHP problem. You have better chances of getting a good quick answer if you posted this in the JavaScript forum.

    Try using: document.forms[0].*


    Dan

    Comment

    • oranoos3000
      New Member
      • Jan 2009
      • 107

      #3
      hello
      f1 is the id of your form?
      you can give name attribute to your form and use

      document.forms["f1"].submit();
      that f1 is value of the name attribute form

      Comment

      Working...