How can i capture values or text selected in drop down menu or in combo box or in any input forms and print it on the same page ?? also the selected value i want to store it in data base. how can i do that??
plzzzz reply soon...!
1)selCombo.html:
<html>
<script>
function selValue(){
var mytext = document.form.sel.options[document.form.sel.selectedIndex].text;
document.getElementById('lab').style.visibility="visible";
document.getElementById('val').style.visibility="visible";
document.form.val.value=mytext;
}
</script>
<form name="form" method="post" action="http://localhost:8080/examples/jsp/save.jsp">
<select name="sel" id="sel" onchange="selValue();">
<option value="<-Select->"><- Select- ></option>
<option value="India">India</option>
<option value="USA">USA</option>
<option value="Srilanka">Srilanka</option>
<option value="Japan">Japan</option>
<option value="Australia">Australia</option>
</select>
<br><br>
<label id="lab" name="lab" style="visibility:hidden;">You have selected:</label><input style="visibility:hidden;" id="val" type="text" name="val" ><br>
<input type="submit" value="Save" >
</html>
2)save.jsp:
<%@page import="java.sql.*"%>
<%
try{
String str=request.getParameter("val");
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");
Statement st=con.createStatement();
int i=st.executeUpdate("insert into country(countryname) values('"+str+"')");
out.println("Inserted Successfully!");
}
catch(Exception e){
System.out.println(e);
}
%>