简体   繁体   English

从查询字符串中检索值,并将其以隐藏值的形式发送-javascript

[英]Retrieve value from query string and send it in a form as HIDDEN VALUE - javascript

I'm trying to figure how to post from an HTML to another page andm, in the meantime, insert values in the hidden form BEFORE send the form itself. 我试图弄清楚如何从HTML发布到另一个页面,同时,在发送表单本身之前,在隐藏的表单中插入值。

 <html> <head> <META HTTP-EQUIV="CONTENT-TYPE" CONTENT="TEXT/HTML;CHARSET=UTF-8"> <META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE"> <META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE"> <META HTTP-EQUIV="EXPIRES" CONTENT="-1"> <script> var param1var = getQueryVariable("TARGET"); function getQueryVariable(variable) { var query = window.location.search.substring(1); var vars = query.split("&"); for (var i=0;i<vars.length;i++) { var pair = vars[i].split("="); if (pair[0] == variable) { alert("TARGET FOUND!"); alert(pair[1]); return pair[1]; } } alert('Query Variable ' + variable + ' not found'); } </script> </head> <form name="LOGIN" action="/mynextpage/mypage.html" method="post"> <table> <tr> <td><P><span>Username :</span></P></td> <td><P><input name="USER" type="text" value="" style="width:150px" /></P></td> </tr> <tr> <td><P><span>Password :</span></P></td> <td><P><input name="PASSWORD" type="password" value="" style="width:150px" /></P></td> </tr> </table> </div> <INPUT type=HIDDEN name="TARGET" value=param1var <P> <input name="submit" type="submit" value="Login" /> <input name="Reset" type="reset" /> </P> </div> </form> 

The first part of the javascript code is able to capture a TARGET value I need to use: it is present (i'm calling it param1var) and I'm able to alert out just for confirmation. javascript代码的第一部分能够捕获我需要使用的TARGET值:它存在(我称其为param1var),并且我能够提醒您进行确认。

Now, in the form, I need to: - insert in the input hidden the value retrieved by the above code (so, the param1var value) - post the entire for to the page /mynextpage/mypage.html that will take username, password and the hidden value 现在,在表单中,我需要:-将上面的代码检索到的值(即param1var值)插入到隐藏的输入中-将整个for张贴到将使用用户名,密码的页面/mynextpage/mypage.html中和隐藏的价值

Can you help me on how to achieve it? 您能帮我实现它吗? I can use only html page as first page. 我只能将html页面用作首页。

Thanks 谢谢

document.querySelector('.target').value=param1var; document.querySelector('。target')。value = param1var; at the same time your hidden input put the class target 同时您隐藏的输入将类目标

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM