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 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器