如何将值从一个窗体发布到另一个窗体? [英] how to Post values from one form to another form?
本文介绍了如何将值从一个窗体发布到另一个窗体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
parent.html
< HTML>
< form name =formmethod =postaction =child2.html>
< input type =textvalue =name =text2id =pdetails2>
< input type = submit name =submitvalue =submit>< / form>
< / html>
child2.html
< HTML>
< form name =form1>
< input type =textvalue =name =text3id =pdetails3>
< / form>< html>
在这里,如果我给父窗体文本框中的任何值一旦我点击提交按钮,我需要文本box value在child2表单文本框中我能做什么?
解决方案
对于您的特定解决方案:您可以使用javascript进行尝试。
1。)更改parent.html表单的方法来获取而不是后期。
code>< form name =formmethod =getaction =child2.html>
<2>)在child2.html中添加以下javascript函数:
< script type =text / javascript>
函数$ _GET(q,s){
s = s? s:window.location.search;
var re = new RegExp('&'+ q +'(?:=([^&] *))?(?=& | $)','i');
return(s = s.replace(/ ^?/,'&')。match(re))? (typeof s [1] =='undefined'?'':decodeURIComponent(s [1])):undefined;
}
< / script>
<3>)使用$ _GET('var1');获得价值:例如在你的文本框中:
< input type =textvalue =name =text3 id =pdetails3>
< script> document.getElementById('pdetails3')。value = $ _GET('pdetails2');< / script>
parent.html
<HTML>
<form name="form" method="post" action="child2.html">
<input type="text" value="" name="text2" id="pdetails2">
<input type=submit name="submit" value="submit"></form>
</html>
child2.html
<HTML>
<form name="form1">
<input type="text" value="" name="text3" id="pdetails3">
</form><html>
here if i give any value in parent form text box once i click on submit button i need that text box valu in child2 form textbox what can i do?
解决方案
For your specific solution: you can try it using javascript.
1.) Change the parent.html 's form's method to get instead of post i.e
<form name="form" method="get" action="child2.html">
2.) In child2.html add the following javascript function:
<script type="text/javascript">
function $_GET(q,s) {
s = s ? s : window.location.search;
var re = new RegExp('&'+q+'(?:=([^&]*))?(?=&|$)','i');
return (s=s.replace(/^?/,'&').match(re)) ? (typeof s[1] == 'undefined' ? '' : decodeURIComponent(s[1])) : undefined;
}
</script>
3.) use $_GET('var1'); to get the value: e.g in ur textbox:
<input type="text" value="" name="text3" id="pdetails3">
<script>document.getElementById('pdetails3').value = $_GET('pdetails2');</script>
这篇关于如何将值从一个窗体发布到另一个窗体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文