嘿我有一个textarea,每次我使用Google api的响应输入时会自动更新,但是当我尝试从该textarea获取值时,它返回null。我知道jsp脚本只运行一次,我不知道每次文本区域的文本发生变化时如何运行。
style
更新textarea的脚本就是这个
<div id="main-wrapper">
<div class="container">
<div class="row">
<div class="col">
<div class="input-field" id="input">
<input placeholder="Hey, ask me something..." id="q"
type="text" type="email" class="form-control"
onKeyDown="if(event.keyCode==13) actionApi();">
</div>
<div id="result"></div>
</div>
<div class="col s5">
<h5>Response payload:</h5>
<h1 id="test"></h1>
<textarea id="jsonResponse" name="parametru">
<%
Connection conn = null;
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost/api?user=root&password=1234");
} catch (SQLException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
String res = request.getParameter("parametru");
out.println(res);
try (PreparedStatement insert = (PreparedStatement) conn
.prepareStatement("insert into test(Id, nume) value(default, ?)")) {
if (res != null)
insert.setString(1, res);
else
insert.setString(1, "aaa");
insert.execute();
} catch (SQLException e) {
e.printStackTrace();
}
%>
</textarea>
</div>
</div>
</div>
</div>
答案 0 :(得分:0)
您应该使用.value
更新textarea值:
document.getElementById("jsonResponse").value = textContent;