This is Interesting: Free Magazines for Graphics designers and webmasters  


Home > Archive > Dreamweaver > February 2006 > How can i get the variable declared in jsp to a javascript function





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author How can i get the variable declared in jsp to a javascript function
Pooja Nair

2006-02-24, 10:15 am

Hello all.
I'm in a trouble.. i was developing a program in jsp oracle. and in
some cases i use java scripts.. here in the HR program module i feel a
trouble.
the code here i'm sending is just a trial one.. the jdbc and all are
doing in the jsp page itslef.

egs.. : there is a table with 4 fields
___________________________________________________________________________
Empid Empname Empdetails
EmpSal
___________________________________________________________________________

and in the table there are 100 records. Emp id is the primary key

here what my problem starts..
i want to list all the emp id in the combo box
for that i used jsp program

now when i select any one emp id i want to display the
empname emp details and emp salary in another 3 text boxes

i have successfully placed all the empid in the combo box
now what i done is i wrote code in java script.. in onchange() for
combo
now i'm not getting the values

here i'm sending the code.. below..
please help me

____________________________________________________________________________

<html>
<head>
<title>DOLOGIN
</title>
</head>
<%@ page language="java" session="true" import="java.sql.*" %>
<body>
<form method="POST" name="form1" action="--WEBBOT-SELF--">
<!--webbot bot="SaveResults"
U-File="fpweb:///_private/form_results.csv" S-Format="TEXT/CSV"
S-Label-Fields="TRUE" -->
<select size="1" name="D1" onchange =xx() >
<option> --Select One--</option>

<%
String age[] = new String[20];
String ph[] = new String[20];
int i=0;
try
{
try
{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e)
{ out.println(e);
}
String dbURL = "jdbc:odbc:trial";
Connection dbCon;
dbCon = DriverManager.getConnection(dbURL);
String query = "Select * from table1";
Statement stmt = dbCon.createStatement();
ResultSet rs = stmt.executeQuery(query);
while(rs.next())
{ String name = rs.getString(1);
//out.println(name);
%>
<option value="<%=name%>"><%=name%></option>
<%
age= rs.getString(2);
ph = rs.getString(3);
//out.println(age);
//out.println(ph);
i++;

}
%>
</select>
<%
out.println(age[4]);
dbCon.close();
stmt.close();
}
catch(SQLException e)
{ response.sendRedirect("error.html");
}
%>

</form>
</body>
</html>

<SCRIPT LANGUAGE=javascript>
<!--
function xx()
{ //alert("aravind")
alert(document.form1.D1.selectedIndex)
alert(document.form1.D1.value)
alert(age[document.form1.D1.selectedIndex]) //this is not executing//
}
//-->
</SCRIPT>
____________________________________________________________________________

here is the code..
i want the age to run here

please help me

Sponsored Links


Copyright 2003 - 2008 forum4designers.com  Software forum  Computer Hardware reviews