Hi...everyone
Below i have attached my code. This code is working.....but i want some modification in that code such that when i select 'vegetable' or 'fruits', it should give list of that selected one in second list, BUT THAT list should be stored in mysql database.
In the below program , i have hard-coded that second list, but i want second list to be dynamic from database.
Please, help me out.
Thank you for your help in advance
[code]
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<BODY BGCOLOR=WHITE onLoad="setList(document.listsform)">
<FORM NAME="listsform">
<SELECT NAME="list1" onChange="setList(form)">
<OPTION>Fruit
<OPTION>Vegetables
<SELECT NAME="list2">
<OPTION>
<OPTION>
<OPTION>
<OPTION>
<OPTION>
<OPTION>
<OPTION>
<OPTION>
<OPTION>
[/code]
Hi Friend,
Try the following code:
1)select.jsp:
<html> <head> <script type="text/javascript"> var xmlHttp; function showState(str){ if (typeof XMLHttpRequest != "undefined"){ xmlHttp= new XMLHttpRequest(); } else if (window.ActiveXObject){ xmlHttp= new ActiveXObject("Microsoft.XMLHTTP"); } if (xmlHttp==null){ alert ("Browser does not support XMLHTTP Request") return } var url="select2.jsp" url=url+"?fooditem="+str xmlHttp.onreadystatechange=stateChanged xmlHttp.open("GET",url,true) xmlHttp.send(null) } function stateChanged(){ if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { document.getElementById("item").innerHTML=xmlHttp.responseText } } function GetXmlHttpObject(){ var xmlHttp=null; try{ xmlHttp=new XMLHttpRequest(); } catch (e) { try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } } return xmlHttp; } </script> </head> <body> <form name="employee"> <br><br> <b>Select Food Item</b> <select name="name" onchange="showState(this.value);"> <option value="-1">Select</option> <option value="fruit">Fruits</option> <option value="vegetable">Vegetables</option> </select> <div id='item'> <b>Select Item </b> <select name='item' > <option value='-1'></option> </select> </div> </form> </body> </html>
2)select2.jsp:
<%@page language="java" import ="java.sql.*" %> <% String fi=request.getParameter("fooditem"); String buffer="<b>Select Item </b> <select><option value='-1'>Select Item</option>"; Class.forName("com.mysql.jdbc.Driver").newInstance(); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root"); Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery("Select * from items where fooditem='"+fi+"' "); while(rs.next()){ buffer=buffer+"<option value='"+rs.getString("item")+"'>"+rs.getString("item")+"</option>"; } buffer=buffer+"</select>"; response.getWriter().println(buffer); %>
3)For the above code, we have created following table:
CREATE TABLE `items` ( `id` bigint(255) NOT NULL auto_increment, `fooditem` varchar(255) default NULL, `item` varchar(255) default NULL, PRIMARY KEY (`id`) )
Thanks
Hey thank you very very much.....I want same answer which you have posted..Thanks a lot:-)
in above code , please i want some modification.....i have tried my best ,but i didn't get.
I want to print checked checkbox on same page in another table. please, help me out
2)select2.jsp
print("code sample");
<%@page language="java" import ="java.sql.*" %> <% String fi=request.getParameter("fooditem"); String buffer="Select Item "+rs.getString("item")+""; } buffer=buffer+""; response.getWriter().println(buffer); %>
print("code sample");