【问题标题】:Unable to change the value of an input in a form to a variable无法将表单中的输入值更改为变量
【发布时间】:2014-08-11 07:47:42
【问题描述】:

这个页面背后的想法是将日志加载到页面上,如果日志中的一行符合我设置的正则表达式的条件。您将能够单击它,并且您单击的行将被传递到另一个页面。我的 javascript 看起来像这样

 <% string variable ="this isnt going to work"; %>

<SCRIPT type="text/javascript">
<!--
function a(){
document.form0.action = "page-to-navigate-to.jsp";
document.getElementById('GenID').value= variable;
//document.getElementById('GenID').value="IF I JUST ENTER TEXT LIKE THIS IT WILL WORK";
document.form0.submit();}
-->
</SCRIPT>

<
 //code here that calls function "a"
>


<FORM name="form0" method="post" target="_blank">
<input type = "hidden" name="GenID">
</FORM>

我已经排除了完成模式匹配的代码部分,因为我什至无法获得一个简单的字符串变量来处理它,但正如 cmets 所提到的。如果我只是输入任何内容,我输入的内容将毫无问题地传递到下一页。

我对 javascript 很陌生,所以我很可能在做一些根本错误的事情

非常感谢您的帮助,谢谢

【问题讨论】:

  • 你需要在脚本标签中输出你的变量:var variable = 'this should work';

标签: javascript html forms jsp variables


【解决方案1】:

这不是 JavaScript,而是服务器端代码。

<% string variable ="this isnt going to work"; %>

你可以这样做:

document.getElementById('GenID').value = "<%=variable%>";

【讨论】:

猜你喜欢
  • 2022-06-15
  • 1970-01-01
  • 2018-10-22
  • 2011-02-02
  • 2021-08-25
  • 1970-01-01
  • 2012-04-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多