如何在提交之前更改隐藏输入字段的值 [英] How to change the value of hidden input field before submitting
问题描述
我有一个带有两个按钮的Feedburner订阅表单,一个用于每日新闻和一个用于每周新闻。问题是如何在提交之前使用名称'uri'更改隐藏输入字段的值?我的解决方案不起作用。
I have a Feedburner subscription form with two buttons, one for daily news and one for weekly news. The question is how to change the value of hidden input field with name 'uri' before submitting? My solution doesn't work.
这是我尝试使用的:
<form id="feedburner" action="https://feedburner.google.com/fb/a/mailverify"
method="post" target="popupwindow">
<p>
<input autocomplete="off" value="Enter your email…"
onblur="if (this.value == '') {this.value = 'Enter your email…';}"
onfocus="if (this.value == 'Enter your email…') {this.value = '';}"
type="text" name="email"/>
<input type="hidden" name="uri"/>
<input type="hidden" name="loc" value="en_US"/>
</p>
<input type="submit" value="Daily" onsubmit="document.getElementsByName('uri').value = 'androidinfodaily'; window.open('https://feedburner.google.com/fb/a/mailverify?uri=androidinfodaily', 'popupwindow'); return true" checked>
<input type="submit" value="Weekly" onsubmit="document.getElementsByName('uri').value = 'androidinfoweekly'; window.open('https://feedburner.google.com/fb/a/mailverify?uri=androidinfoweekly', 'popupwindow'); return true">
</form>
解决
我修复了我的代码,现在它可以工作。这是最后的变体:
I have fixed my code and now it works. This is the final variant:
<form id="feedburner" action="https://feedburner.google.com/fb/a/mailverify"
method="post" target="popupwindow">
<p>
<input autocomplete="off" value="Enter your email…"
onblur="if (this.value == '') {this.value = 'Enter your email…';}"
onfocus="if (this.value == 'Enter your email…') {this.value = '';}"
type="text" name="email"/>
<input type="hidden" name="uri" />
<input type="hidden" name="loc" value="en_US"/>
</p>
<input type="submit" value="Daily" onclick="document.getElementsByName('uri')[0].value = 'androidinfodaily'; window.open('https://feedburner.google.com/fb/a/mailverify?uri=androidinfodaily', 'popupwindow'); return true">
<input type="submit" value="Weekly" onclick="document.getElementsByName('uri')[0].value = 'androidinfoweekly'; window.open('https://feedburner.google.com/fb/a/mailverify?uri=androidinfoweekly', 'popupwindow'); return true">
</form>
推荐答案
The submit event is fired on the form element, not on submit button, so use click handlers
请注意,仅在表单元素上触发提交,而不是按钮或
提交输入。 (表单被提交,而不是按钮。)
Note that submit is fired only on the form element, not the button or submit input. (Forms are submitted, not buttons.)
<form id="feedburner" action="https://feedburner.google.com/fb/a/mailverify"
method="post" target="popupwindow">
<p>
<input autocomplete="off" value="Enter your email…"
onblur="if (this.value == '') {this.value = 'Enter your email…';}"
onfocus="if (this.value == 'Enter your email…') {this.value = '';}"
type="text" name="email"/>
<input type="hidden" name="uri"/>
<input type="hidden" name="loc" value="en_US"/>
</p>
<input type="submit" value="Daily" onclick="document.getElementsByName('uri')[0].value = 'androidinfodaily'; window.open('https://feedburner.google.com/fb/a/mailverify?uri=androidinfodaily', 'popupwindow'); return true" checked>
<input type="submit" value="Weekly" onclick="document.getElementsByName('uri')[0].value = 'androidinfoweekly'; window.open('https://feedburner.google.com/fb/a/mailverify?uri=androidinfoweekly', 'popupwindow'); return true">
</form>
另外,将脚本分割为像
Also it will be better to speprate the script to a function like
<form id="feedburner" action="https://feedburner.google.com/fb/a/mailverify" method="post" target="popupwindow">
<p>
<input autocomplete="off" value="Enter your email…" onblur="if (this.value == '') {this.value = 'Enter your email…';}" onfocus="if (this.value == 'Enter your email…') {this.value = '';}" type="text" name="email" />
<input type="hidden" name="uri" />
<input type="hidden" name="loc" value="en_US" />
</p>
<input type="submit" value="Daily" onclick="return beforeSubmit('androidinfodaily')" checked />
<input type="submit" value="Weekly" onclick="return beforeSubmit('androidinfoweekly')" />
</form>
然后
then
function beforeSubmit(type) {
document.getElementsByName('uri')[0].value = type;
window.open('https://feedburner.google.com/fb/a/mailverify?uri=' + type, 'popupwindow');
return true
}
这篇关于如何在提交之前更改隐藏输入字段的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!