0

I have populated my dropdown menu using the database and I want to get the value of the option that the user will be selecting.

For example I have a dropdown menu with different usernames (1002,1003,1004) and if the user select 1003 then I want to get that id and redirect according to the id.

<form action="record.jsp" method="POST">
   <select name="">
      <sql:setDataSource var="con"
         driver="org.apache.derby.jdbc.ClientDriver" url="jdbc:derby://localhost:1527/dbechannel"
         user="inuri" password="inuri" />
      <sql:query var="h" scope="session" dataSource="${con}">
         <%--setting the datasource value // --%>
         SELECT * FROM USERPROFILE where usertype='user'
      </sql:query>
      <c:forEach var="i" items="${h.rows}">
         <option></option>
         <option> ${i.username}
      </c:forEach>
   </option>

   </br>
      <input type="submit" value="Search User" />
   </select>

</form>

please help if anyone knows how to get the result of this drop down menu to a variable

Vinoth Krishnan
  • 2,925
  • 6
  • 29
  • 34
inuri
  • 1
  • You have to use Javascript to get the selected value. (i.e) onchange function. See [sample](https://stackoverflow.com/questions/12080098/dropdown-using-javascript-onchange) onchange SO answers. – Vinoth Krishnan Nov 17 '17 at 10:30
  • thankyou but how do you give a value to each option when the options are retrieved from the database and is displayed by iterating through a for each loop? – inuri Nov 19 '17 at 03:25
  • You can set id of user to the option value like ``. Hence it will generate the options like ``. In your Javascript you can get the value of option (i.e) 123. – Vinoth Krishnan Nov 20 '17 at 06:31

0 Answers0