How to switch the action field in an HTML form dynamically


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <SCRIPT language="JavaScript">
  2. function OnSubmitForm()
  3. {
  4. if(document.pressed == 'Insert')
  5. {
  6. document.myform.action ="insert.html";
  7. }
  8. else
  9. if(document.pressed == 'Update')
  10. {
  11. document.myform.action ="update.html";
  12. }
  13. return true;
  14. }
  15. </SCRIPT>
  16.  
  17. <FORM name="myform" onSubmit="return OnSubmitForm();">
  18.  
  19. <INPUT TYPE="SUBMIT" name="Operation" onClick="document.pressed=this.value" VALUE="Insert">
  20.  
  21. <INPUT TYPE="SUBMIT" name="Operation" onClick="document.pressed=this.value" VALUE="Update">
  22.  
  23. </FORM>

URL: http://www.javascript-coder.com/html-form/html-form-action.phtml

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.