Hello there,
Am sending a sample code below. Please evaluate it & send me a reply as
to what the heck is wrong with it.
What I tried to do was this:
a)Populate a list box("vegentries") in a JSP page with the column
"vegnames" from the table "vegetables".
Status of task: Successful
b)Based on the list selection, the value from "vegentries" must be taken
& put into a hidden textfield when the onChange()="getValueFromList()"
for List selection function is invoked thru' JavaScript.
Status of task: Partial
onChange() doesn't seem to be working!!So I also tried calling
"getValueFromList()" thru' onClick() invoked thru' Button. This works,
but leads me to the next problem
c)Using <% ponumber=request.getParameter(hiddentf) %> in another JSP
called "Second.jsp" , I must be able to retrieve the value of the
selected "veg name" from the List Box in the previous JSP , to a
pre-declared string variable "svegname" in "Second.jsp". This JSp has to
be invoked when the "Submit" button of the First JSP is clicked. Then
how will I trap "onClick()".? how will I call a JSP from a JavaScript
function ?
<HTML>
<HEAD>
<TITLE> List SCREEN </TITLE>
<SCRIPT LANGUAGE="JavaScript">
function getValueFromList()
{
var orderString=""
var n=document.diner.vegentries.length
for(i=0;i<n;i++)
{
if(document.diner.vegentries.options[i].selected)
{
orderString=document.diner.vegentries.options[i].value
}
}
document.diner.visitext.value=orderString
document.diner.hiddentf.value=orderString
}
}
</SCRIPT>
</HEAD>
<BODY>
<FORM NAME="diner" ACTION="http://localhost:8080/examples/Second.jsp">
<h4 align="center"> Fruit List </h4>
<SELECT NAME="fruitentries" SIZE="4">
<option value="Apple">Apple </option>
<option value="Orange">Orange </option>
<option value="Grapes">Grapes </option>
<option value="Guava">Guava </option>
</SELECT>
<p><b> You Ordered: </b>
<p>
<%@page language="java" contentType="text/html" session="true" %>
<%! java.sql.Connection con; %>
<%! java.sql.Statement stmt; %>
<%! java.sql.ResultSet rs; %>
<%! java.util.Vector vegvector; %>
<% vegvector = new java.util.Vector(); %>
<% Class.forName ("COM.ibm.db2.jdbc.app.DB2Driver");
con =
java.sql.DriverManager.getConnection("jdbc:db2:SAMPLE","db2admin","db2admin");
stmt = con.createStatement();
rs = stmt.executeQuery("SELECT DISTINCT(vegname) FROM
vegetables");
while(rs.next())
{
povector.addElement(rs.getString("vegname"));
}
%>
<%
out.println("<select name='vegentries' size='4'
onChange=/"getValueFromList()/">");
for(int i=0; i<povector.size();i++)
{
out.println("<option value=''>"+vegvector.elementAt(i)+"</option>");
}
out.println("</select>");
%>
<input type="text" name="visitext" cols="20" rows="4">
<p>
<input type="hidden" name="hiddentf" cols="20" rows="4">
<p>
<input type="Submit" name="order" value="Let Me Have It" >
</form>
</BODY>
</HTML>
Kindly help me out ....
Thanx in advance.....
Rgds,
Mythili
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html