在使用javascript提交之前更改表单元素 [英] change form element before submit with javascript

查看:101
本文介绍了在使用javascript提交之前更改表单元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的代码中,我能够获得警报消息,以正确显示消息和数字3。有人知道如何使用通过变量/数字来声明一个名为优先级的表单元素在提交之前传递给表单吗?



我的目标是使用 $ _ POST [priority] ,然后根据点击链接/按钮生成数字1,2或3.

 < script language =JavaScript> 
函数submitForm(优先级)
{
alert(更改为优先级+优先级);
document.frm.submit();
}
< / script>

< a href =javascript:submitForm('3'); class =ddm>< span class =label> Low< / span>< / a>
< a href =javascript:submitForm('2'); class =ddm>< span class =label>中< / span>< / a>
< a href =javascript:submitForm('1'); class =ddm>< span class =label>高< / span>< / a>


解决方案

您不需要任何脚本,使用3提交按钮:

 < button type =submitname =priorityvalue =1> Priority 1<按钮> 
< button type =submitname =priorityvalue =2> Priority 2< / button>
< button type =submitname =priorityvalue =3> Priority 3< / button>

只有被点击的人才会将其值发送给服务器。

In the below code I am able to get the alert message to display correctly displaying the message and the number "3". Does anyone know how to use that passes variable/number to declare a form element named "priority" to be passed to the form before submitting?

My goal is to use $_POST["priority"] and generate the number 1, 2, or three based on which link/button is clicked.

 <script language="JavaScript">
    function submitForm(priority)
    {
      alert("Changing to Priority " + priority);
      document.frm.submit();
    }
 </script>

<a href="javascript: submitForm('3');" class="ddm"><span class="label">Low</span></a>
<a href="javascript: submitForm('2');" class="ddm"><span class="label">Medium</span></a>
<a href="javascript: submitForm('1');" class="ddm"><span class="label">High</span></a>

解决方案

You don't need any script, use 3 submit buttons:

<button type="submit" name="priority" value="1">Priority 1</button> 
<button type="submit" name="priority" value="2">Priority 2</button> 
<button type="submit" name="priority" value="3">Priority 3</button> 

Only the one that is clicked will send it's value to the server.

这篇关于在使用javascript提交之前更改表单元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆