Set a form's action attribute when submitting?

后端 未结 7 1209
情话喂你
情话喂你 2020-12-03 00:45

How do I change a form\'s action attribute right after clicking the submit button?

相关标签:
7条回答
  • 2020-12-03 01:44

    You can do that on javascript side .

    <input type="submit" value="Send It!" onClick="return ActionDeterminator();">
    

    When clicked, the JavaScript function ActionDeterminator() determines the alternate action URL. Example code.

    function ActionDeterminator() {
      if(document.myform.reason[0].checked == true) {
        document.myform.action = 'http://google.com';
      }
      if(document.myform.reason[1].checked == true) {
        document.myform.action = 'http://microsoft.com';
        document.myform.method = 'get';
      }
      if(document.myform.reason[2].checked == true) {
        document.myform.action = 'http://yahoo.com';
      }
      return true;
    }
    
    0 讨论(0)
提交回复
热议问题