I am new here. I am trying to store a JavaScript variable in a session by using hidden fields and submitting a form:
function populateInput()
{
rowClicked = true;
var key = document.getElementById("key").innerText;
var value = document.getElementById("value").innerText;
document.getElementById("key2").value = key;
document.getElementById("value2").value = value;
var form = document.getElementById("output");
form.submit();
}
which will be called by:
<html>
<tr id="row" onclick="populateInput()"
</html>
The object is to take the values from a row, which contains two columns, a key and a value (stored in a HashMap), and pass them to another jsp, so that they can be displayed in two text boxes (one for key and one for value) by clicking a row on another jsp.
The trouble I am having is with setting the attribute within scriptlets. I am getting the innerText of a td element, and assigning it to a variable in JavaScript and then passing it to the value of an HTML DOM object.
Then I want to submit this to another form using scriptlets (<%request.setAttribute%>), but how? I realize that by using scriptlets, you're using Java code, which is not an HTML attribute.
Any help would be highly appreciated.
Here is the whole table:
<%if (m != null){%>
<%for (Map.Entry<String, String> e : m.entrySet()){ %>
<tr id="row" onclick="populateInput()">
<td id="key"><%=e.getKey() %></td>
<td id="value"><%=e.getValue() %></td>
</tr>
<%} %>
<%} %>
I want to get the innerText of the td elements, store them into the vars, key, and value, and then store those vars into the value of:
<input type="hidden" id="key2">
<input type="hidden" id="value2">
The trouble I am having is with setting the value of the hidden fields using request.setAttribute("", obj) in scriptlets, and submitting them to the other form.