java - Trying to get value out of a select option in the same form -
i'm trying value out of select option. doesn't seems able since it's on form. how do ? mean having taking value out of option select.
<strong>select product :</strong> <select name="stockid"> <c:foreach var="row" items="${stocks1.rowsbyindex}"> <option selected><c:out value="${row[0]}"/></option> </c:foreach> </select> </p> <%!int query = 0; %> <% if(request.getparameter("stockid") != null){ connection connection = drivermanager.getconnection( "jdbc:derby://localhost:1527/healthdb", "nbuser", "nbuser"); preparedstatement statement = connection.preparestatement("select stockqty stocks stockid = ?"); statement.setstring(1,request.getparameter("stockid")); resultset resultset = statement.executequery( ) ; if(resultset.next()){ out.print(resultset.getstring("stockqty")); query = resultset.getint("stockqty"); } else out.print("lol");}%>
1.) can not select items in select selected
! without multiple="multiple"
<c:foreach var="row" items="${stocks1.rowsbyindex}"> <option selected><c:out value="${row[0]}"/></option> </c:foreach>
e.g. topfr[]
<select name = "topfr[]" multiple="multiple"> <option selected="selected">apple</option> <option>pear</option> <option selected="selected">peach</option> </select>
if can have multiple selected name
must array here stockid[]
<select name="stockid[]">
if <form>
array must treat request.getparameter("stockid")
as array
!
2.) or stockid = int then
you can not pass string field = int
if stockid
int !
statement.setstring(1,request.getparameter("stockid"));
will set string query , string quoted
wrong
select stockqty stocks stockid = "1"
you need
select stockqty stocks stockid = 1
try
statement.setint(1,integer.parseint(request.getparameter("stockid"));
also should test empty !
string res = request.getparameter("stockid"); if(res != null && !res.isempty()){
Comments
Post a Comment