I have a dropdownbox written in HTML which takes different categories from a MYSQL-database.
<td><form:select path="categoryName">
<form:option value="NONE" label="--- Select Category ---" ></form:option>
<form:options items="${categoryList2}" ></form:options>
</form:select></td>
The question I have is if I can use the selected category from that dropdownbox and use it in javascript code. Is it possible or do I need to re-create the box in html to javascript instead.
Many comments say that I should have the same problem as the other forum-thread. But I want to use this in a SQL-prepeared statement from java. So far I have this:
var e = document.getElementById("categoryName");
var selectItem = e.options[e.selectedIndex].text;
var theData = [ // Start of JavaScript data object
<%
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/pyramid", "root", "test");
PreparedStatement ps = con.prepareStatement("SELECT timeStamp, value FROM status WHERE idCategory = (SELECT idCategory FROM category WHERE name =*' "+ %> + selectItem + <% + " '*)");
ResultSet rs = ps.executeQuery();
while (rs.next()) {
%>
[" <%= rs.getString(1)%>",<%= rs.getString(2)%>],
<%
};
The part where I wanna use the selectItem in the preaperedStatement does not work. Please help someone
Thanks