• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

passing jsp variable to java script function on same page

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello everybody
my problem is that i am execute a database query on a jsp page and want's to send this value to a java script function.
after that i want to access this value at java script function and wants to perform some operation over that value
i am also giving a sample code of my project idea.

the jsp part:
<html>
<body>
<form name="form1" method="post" action="">
<p>
<input type="text" name="textfield">
</p>
<%
try
{
Connection con=null;
ResultSet rs=null;
Statement stmt=null;
String nam=request.getParameter("textfield");
Class.forName("com.mysql.jdbc.Driver");
con = java.sql.DriverManager.getConnection("jdbc:mysql:///name",
"root","");
stmt= con.createStatement();
rs=stmt.executeQuery("select city from login where name='"+nam+"'");
String NameOfVariable=rs.getString(1);
%>
<p>
<input type="submit" name="Submit" value="Submit" >
</p>
</form>
</body>
</html>

i want to pass the value of NameOfVariable to javascript function valid()

the script part:
<script type="text/javascript">
function valid()
{
}
</script>


is that possible?
if yes then please tell me how
thankx
:abhishek paliwal
 
Ranch Hand
Posts: 541
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Although I wouled rename your variable to something more readable and use standard naming conventions, ie personName.

The thing to remember is that Javascript is just like HTML. So anything in your JSP you output can be put inside a javascript function. The javascript will be created and sent to the users browser.
[ June 25, 2005: Message edited by: Tim Baker ]
 
abhishek paliwal
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thankx for replie ,sir
actually i want to send the value of jsp variable to java script function as an argument.
so will you send me a sample code for this problem.
thanx sir
:abhishek paliwal
 
Tim Baker
Ranch Hand
Posts: 541
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Given what I said you really should be able to work that out.

Seems as I don't know where you want to call the valid function from, i've just put it in another function, you can put it whereever your call is. Perhaps in the onload() event of the body.
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by abhishek paliwal:
thankx for replie ,sir
actually i want to send the value of jsp variable to java script function as an argument.
so will you send me a sample code for this problem.
thanx sir



According to me, you are going in wrong direction. JSP is a server-side technology and executes on the server then sent to the client. However, javascript executes on client-side.
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic