如何在提交[求助]之前更改隐藏输入字段的值 [英] How to change the value of hidden input field before submitting [SOLVED]

查看:132
本文介绍了如何在提交[求助]之前更改隐藏输入字段的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有两个按钮的Feedburner订阅表单,一个用于每日新闻和一个用于每周新闻。问题是如何在提交之前使用名称​​'uri'更改隐藏输入字段的值?我的解决方案不起作用。



这是我尝试使用的方法:

 < form id =feedburneraction =https://feedburner.google.com/fb/a/mailverify
method =posttarget =popupwindow>
< p>
< input autocomplete =offvalue =输入您的电子邮件...
onblur =if(this.value ==''){this.value ='Enter your email ...';}
onfocus =if(this.value =='Enter your email ...'){this.value ='';}
type =textname =email/>
< input type =hiddenname =uri/>
< input type =hiddenname =locvalue =en_US/>
< / p>

< input type =submitvalue =Dailyonsubmit =document.getElementsByName('uri')。value ='androidinfodaily'; window.open('https:// feedburner。 google.com/fb/a/mailverify?uri=androidinfodaily','popupwindow'); return truechecked>

< input type =submitvalue =Weeklyonsubmit =document.getElementsByName('uri')。value ='androidinfoweekly'; window.open('https:// feedburner。 google.com/fb/a/mailverify?uri=androidinfoweekly','popupwindow'); return true>

< / form>

更新

感谢所有收到的答复,我修复了我的代码,现在它可以工作。这是最后的变体:

 < form id =feedburneraction =https://feedburner.google.com / fb / a / mailverify
method =posttarget =popupwindow>
< p>
< input autocomplete =offvalue =输入您的电子邮件...
onblur =if(this.value ==''){this.value ='Enter your email ...';}
onfocus =if(this.value =='Enter your email ...'){this.value ='';}
type =textname =email/>
< input type =hiddenname =uri/>
< input type =hiddenname =locvalue =en_US/>
< / p>

< input type =submitvalue =Dailyonclick =document.getElementsByName('uri')[0] .value ='androidinfodaily'; window.open('https:/ /feedburner.google.com/fb/a/mailverify?uri=androidinfodaily','popupwindow'); return true>

< input type =submitvalue =Weeklyonclick =document.getElementsByName('uri')[0] .value ='androidinfoweekly'; window.open('https:/ /feedburner.google.com/fb/a/mailverify?uri=androidinfoweekly','popupwindow'); return true>

< / form>


解决方案

提交事件,因此请使用点击处理程序


请注意,仅在表单元素上触发提交,而不是按钮或
提交输入。 (表单被提交,而不是按钮。)




 < form id =feedburneraction =https://feedburner.google.com/fb/a/mailverify
method =posttarget =popupwindow>
< p>
< input autocomplete =offvalue =输入您的电子邮件...
onblur =if(this.value ==''){this.value ='Enter your email ...';}
onfocus =if(this.value =='Enter your email ...'){this.value ='';}
type =textname =email/>
< input type =hiddenname =uri/>
< input type =hiddenname =locvalue =en_US/>
< / p>

< input type =submitvalue =Dailyonclick =document.getElementsByName('uri')[0] .value ='androidinfodaily'; window.open('https:/ /feedburner.google.com/fb/a/mailverify?uri=androidinfodaily','popupwindow'); return truechecked>

< input type =submitvalue =Weeklyonclick =document.getElementsByName('uri')[0] .value ='androidinfoweekly'; window.open('https:/ /feedburner.google.com/fb/a/mailverify?uri=androidinfoweekly','popupwindow'); return true>

< / form>






另外,将脚本分割为像

这样的功能

 < form id =feedburneraction =https://feedburner.google.com/fb/ a / mailverifymethod =posttarget =popupwindow> 
< p>
< input autocomplete =offvalue =Enter your email ...onblur =if(this.value ==''){this.value ='Enter your email ...';}onfocus = if(this.value =='Enter your email ...'){this.value ='';}type =textname =email/>
< input type =hiddenname =uri/>
< input type =hiddenname =locvalue =en_US/>
< / p>
< input type =submitvalue =Dailyonclick =return beforeSubmit('androidinfodaily')checked />
< input type =submitvalue =Weeklyonclick =return beforeSubmit('androidinfoweekly')/>
< / form>

然后

  function beforeSubmit(type){
document.getElementsByName('uri')[0] .value = type;
window.open('https://feedburner.google.com/fb/a/mailverify?uri='+ type,'popupwindow');
return true
}


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.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>

UPDATE

Thanks to all received responses 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屋!

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