通过表单传递 JS 变量
Passing a JS variable through the form
在下面的form
中,我需要document.result[0].value
作为表单变量传递给onclick
的值到下一页吗?具体而言,此document.result[0].value=totalquestions-incorrect.length+ value
需要作为表单数据在store_result.cfm
页面上访问。
<form method="POST"><div
align="center"><center><p>
<script>
var wrong=0
for (e=0;e<=2;e++)
document.result[e].value=""
var results=document.cookie.split(";")
for (n=0;n<=results.length-1;n++){
if (results[n].charAt(1)=='q')
parse=n
}
var incorrect=results[parse].split("=")
incorrect=incorrect[1].split("/")
if (incorrect[incorrect.length-1]=='b')
incorrect=""
document.result[0].value=totalquestions-incorrect.length+" out of "+totalquestions
document.result[2].value=(totalquestions-incorrect.length)/totalquestions*100+"%"
for (temp=0;temp<incorrect.length;temp++)
document.result[1].value+=incorrect[temp]+", "
</script>
<input type="button" value="Continue" name="B1"
onClick="location.href='store_result.cfm';""></p>
</center></div>
</form>
// html
<input id='res' type='hidden' value=''>
<script>
var result = 0
// your script here
// calculate the value of result as you wish
$('#res').val(result);
</script>
html:
<input type="button" value="Continue" name="B1" onclick="location.href='store_result.cfm?'+document.result[0].value;" />
store_result.cfm:
<script>
var yourVar = location.href.split('?')[1];
</script>
或者你可以设置饼干。
更改
<input type="button" value="Continue" name="B1" onClick="location.href='store_result.cfm';"">
自
<input type="button" value="Continue" name="B1" onClick="location.href='store_result.cfm?result=' + escape(document.result[0].value);"">
然后,它将通过下一页的查询字符串提供。
相关文章:
- JS变量返回的对象不是值
- 我怎么能让流星简单模式中的一个字段等于一个js变量,并且仍然让用户填写简单模式的其余部分
- 向AngularJS目录添加JS变量
- 在使用cq:include包含外部JS之前,如何在JSP中包含全局JS变量
- 将PHP数组传递给js变量
- 如何从谷歌脚本中获取JS变量
- 敲除js变量设置类似于调用函数
- 带破折号的Ractive.js变量
- jQuery在MVC应用程序中设置JS变量
- HTML按钮获胜't更改JS变量
- 在跨子域上将JS变量从子Iframe传递给父JSP
- 理解bootstrap.js变量声明
- 使用HTML标记中的JS变量在Javascript中动态创建HTML
- 访问JQuery中的vue-js变量
- AJAX将JSON数组保存到多个JS变量中
- 在构造控制器、服务等时作为函数参数传递之前列出的角度 JS 变量
- 将JS变量作为文本返回以发送到Google Analytics
- 将JS变量传递到php数组
- 如何将JS变量异步发送到Rails
- 正在读取JS变量