doushou8730 2015-07-15 19:56
浏览 469
已采纳

如何通过Select onChange与Submit Button提交表单

I need assistance determining when my form was submitted via an onChange event for a Select as opposed to the user clicking on the Submit button.

To complicate matters, I need to be able to identify the difference in PHP.

Sample HTML:

<form name='editdata' method='post' action='/editpage/recordnumber'>
<select name='select1' onchange='this.form.submit()'><options...></select> 
<select name='select2' onchange='this.form.submit()'><options...></select>
<select name='select3' onchange='this.form.submit()'><options...></select> 
<input type='submit' value='Submit' />
</form>

Ultimately, I just need something to latch onto using PHP that identifies whether the form was submitted by an onChange event or by a press of the Submit button.

So far I have found that I can name my submit button 'submit'. This will set $_POST['submit'], thereby telling me that the user clicked the button. However, my onChange event this.form.submit() which is applied to a couple of my Selects stops functioning when I add the name attribute to my submit button.

If I could add some sort of queryString to the end of my submit URL with one method or the other, I think that would get the job done.

  • 写回答

2条回答 默认 最新

  • dowe98261 2015-07-15 20:00
    关注

    You could set a hidden field which gets updated by the event:

    <form name='editdata' method='post' action='/editpage/recordnumber'>
    <input type="hidden" name="submitted_on_change" value="0">
    <select name='select1' onchange='form_submit()'><options...></select> 
    <select name='select2' onchange='form_submit()'><options...></select>
    <select name='select3' onchange='form_submit()'><options...></select> 
    <input type='submit' value='Submit' />
    </form>
    
    <script>
    var form_submit = function() {
       // update the hidden field to 1
       // then submit the form
    }
    </script>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
  • ¥15 NX MCD仿真与博途通讯不了啥情况
  • ¥15 win11家庭中文版安装docker遇到Hyper-V启用失败解决办法整理
  • ¥15 gradio的web端页面格式不对的问题
  • ¥15 求大家看看Nonce如何配置
  • ¥15 Matlab怎么求解含参的二重积分?
  • ¥15 苹果手机突然连不上wifi了?