javascript 文本框值到 scriptlet

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8418615/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 03:23:21  来源:igfitidea点击:

textbox value to scriptlet

javascripthtmlformsvariablesscriptlet

提问by joanna

    <form name="myForm" method="post" onsubmit="return getComment()">
        <textarea id="commentarea"></textarea>
        <input type="text" name="locate" value="<%=rs.getString("location")%>">
        <input type="submit" value="View Comment">
    </form>


    function getComment(){
      <% String locate=request.getParameter("locate"); %>
      var location = <%= locate%>;
      document.getElementById('commentarea').value=location;
      return false;
    }

Everytime i click View Comment, there's no value printed. I want to access locate in the scriptlet and print the value in the text area. I know this is not the best way to access it, but i need to access it in this way. Can anyone help me?

每次我点击查看评论时,都没有打印任何值。我想在 scriptlet 中访问 locate 并在文本区域中打印值。我知道这不是访问它的最佳方式,但我需要以这种方式访问​​它。谁能帮我?

采纳答案by Manjula

You have missed double/single quotes for the value of the location variable. If you don't need to submit the form, just use a button input element.

您错过了位置变量值的双引号/单引号。如果您不需要提交表单,只需使用按钮输入元素。

<form name="myForm" method="post">
        <textarea id="commentarea"></textarea>
        <input type="text" name="locate" value="<%=rs.getString("location")%>">
        <input type="button" value="View Comment" onclick="getComment()">
    </form>


function getComment(){
  <% String locate=request.getParameter("locate"); %>
  var location = "<%= locate%>";
  document.getElementById('commentarea').value = location;
}