admin管理员组文章数量:1365850
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.
This is what I try to use:
<form id="feedburner" action=""
method="post" target="popupwindow">
<p>
<input autoplete="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('', 'popupwindow'); return true" checked>
<input type="submit" value="Weekly" onsubmit="document.getElementsByName('uri').value = 'androidinfoweekly'; window.open('', 'popupwindow'); return true">
</form>
Solved
I have fixed my code and now it works. This is the final variant:
<form id="feedburner" action=""
method="post" target="popupwindow">
<p>
<input autoplete="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('', 'popupwindow'); return true">
<input type="submit" value="Weekly" onclick="document.getElementsByName('uri')[0].value = 'androidinfoweekly'; window.open('', 'popupwindow'); return true">
</form>
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.
This is what I try to use:
<form id="feedburner" action="https://feedburner.google./fb/a/mailverify"
method="post" target="popupwindow">
<p>
<input autoplete="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./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./fb/a/mailverify?uri=androidinfoweekly', 'popupwindow'); return true">
</form>
Solved
I have fixed my code and now it works. This is the final variant:
<form id="feedburner" action="https://feedburner.google./fb/a/mailverify"
method="post" target="popupwindow">
<p>
<input autoplete="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./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./fb/a/mailverify?uri=androidinfoweekly', 'popupwindow'); return true">
</form>
Share
Improve this question
edited May 1, 2018 at 16:03
Cœur
38.8k26 gold badges205 silver badges277 bronze badges
asked Jul 20, 2015 at 11:48
IurieIurie
2,2583 gold badges26 silver badges43 bronze badges
0
3 Answers
Reset to default 5The 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./fb/a/mailverify"
method="post" target="popupwindow">
<p>
<input autoplete="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./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./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./fb/a/mailverify" method="post" target="popupwindow">
<p>
<input autoplete="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./fb/a/mailverify?uri=' + type, 'popupwindow');
return true
}
You can have click event handler for button and change type of button to type="button"
so that it will not submit the form directly. Inside click handler assign balue to uri
input and then submit the form.
HTML:
<form id="feedburner" action="https://feedburner.google./fb/a/mailverify"
method="post" target="popupwindow">
<p>
<input autoplete="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="button" value="Daily" id="daily">
<input type="button" value="Weekly" id="weekly">
</form>
jQuery:
$(function(){
$('#daily').click(function(){
$('input[name="uri"]').val('androidinfodaily');
window.open('https://feedburner.google./fb/a/mailverify?uri=androidinfodaily', 'popupwindow');
//submit form
$('#feedburner').submit();
});
$('#weekly').click(function(){
$('input[name="uri"]').val('androidinfodaily');
window.open('https://feedburner.google./fb/a/mailverify?uri=androidinfoweekly', 'popupwindow');
//submit form
$('#feedburner').submit();
});
});
do not forget [0]
for the first element:
document.getElementsByName('uri')[0].value = 'androidinfodaily';
本文标签: javascriptHow to change the value of hidden input field before submittingStack Overflow
版权声明:本文标题:javascript - How to change the value of hidden input field before submitting - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743757894a2533842.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论