Passing variable value from javascript to jsp page at run time

Reply

Join Date: Sep 2006
Posts: 4
Reputation: vijaysdon is an unknown quantity at this point 
Solved Threads: 0
vijaysdon's Avatar
vijaysdon vijaysdon is offline Offline
Newbie Poster

Passing variable value from javascript to jsp page at run time

 
0
  #1
Sep 16th, 2006
How can we pass the variable value from javascript to jsp page at runtime? I am getting this problem when i want to display the second drop down box according to the selected item in the first drop down.
For ex: Lets consider we have a drop down field named Gender(Male,Female).
If we select Male then the next Drop Down has to be shown as (Kumar, Mr,...)
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,534
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 275
Moderator
masijade's Avatar
masijade masijade is offline Offline
Posting Maven

Re: Passing variable value from javascript to jsp page at run time

 
0
  #2
Sep 16th, 2006
You can't. JSP runs on the server, Javascript (which is NOT Java) runs on the client. You might want to look into something like AJAX which will allow your javascript to make a complete connection to the server, receive data, and then update your page, which will make it look like you are doing what you are asking, but it takes longer than a true programmatic connection.

P.S. Don't come back and ask for more info concerning AJAX. That is another thing does not belong on this forum.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 8
Reputation: ukbasak is an unknown quantity at this point 
Solved Threads: 0
ukbasak ukbasak is offline Offline
Newbie Poster

Re: Passing variable value from javascript to jsp page at run time

 
0
  #3
Apr 23rd, 2009
Request all developer to send codes....

Thanks in advance
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,534
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 275
Moderator
masijade's Avatar
masijade masijade is offline Offline
Posting Maven

Re: Passing variable value from javascript to jsp page at run time

 
0
  #4
Apr 23rd, 2009
Originally Posted by ukbasak View Post
Request all developer to send codes....

Thanks in advance
What a maroon.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 21
Reputation: amarjeetsingh has a little shameless behaviour in the past 
Solved Threads: 1
amarjeetsingh amarjeetsingh is offline Offline
Newbie Poster

Re: Passing variable value from javascript to jsp page at run time

 
0
  #5
Apr 24th, 2009
Yes u can do it

but u hv to speicify from where do u want
to display the list of all the the male members

if u want that value to be get from the database
then u can use ajax from ur current jsp page


This is the Demo for ur help

  1. <html>
  2. <head>
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9. </head>
  10.  
  11.  
  12.  
  13. <body>
  14. <script type="text/javascript">function ajaxFunction()
  15. {var xmlHttp;
  16. try
  17. { // Firefox, Opera 8.0+, Safari
  18. xmlHttp=new XMLHttpRequest();
  19. }
  20. catch (e)
  21. { // Internet Explorer
  22. try
  23. { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }
  24. catch (e)
  25. { try
  26. { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
  27. catch (e)
  28. { alert("Your browser does not support AJAX!"); return false; } } }
  29. xmlHttp.onreadystatechange=function()
  30. {
  31. //alert("i m not in ready state");
  32.  
  33. if(xmlHttp.readyState==0)
  34. {
  35. //document.myForm.time.value=xmlHttp.responseText;
  36. alert("The request is not initialized");
  37.  
  38.  
  39.  
  40.  
  41.  
  42. }
  43. if(xmlHttp.readyState==1)
  44. {
  45. //document.myForm.time.value=xmlHttp.responseText;
  46. alert("The request has been set up");
  47.  
  48.  
  49.  
  50.  
  51.  
  52. }
  53.  
  54.  
  55.  
  56. if(xmlHttp.readyState==2)
  57. {
  58. //document.myForm.time.value=xmlHttp.responseText;
  59. alert("The request has been sent");
  60.  
  61.  
  62.  
  63.  
  64.  
  65. }
  66.  
  67. if(xmlHttp.readyState==3)
  68. {
  69. //document.myForm.time.value=xmlHttp.responseText;
  70. alert("The request is in process");
  71.  
  72.  
  73.  
  74.  
  75.  
  76. }
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85. if(xmlHttp.readyState==4)
  86. {
  87. //document.myForm.time.value=xmlHttp.responseText;
  88. //alert("i m in ready state");
  89.  
  90. document.getElementById("theResponse").innerHTML = xmlHttp.responseText;
  91.  
  92.  
  93.  
  94. }
  95. }
  96. var gender=document.myForm.gender.value;
  97. var url="getAllGender.jsp";
  98. url=url+"?gender="+gender+"&sid="+Math.random();
  99. //url=url+"&sid="+Math.random();
  100.  
  101.  
  102.  
  103. xmlHttp.open("GET",url,true);
  104. xmlHttp.send(null);
  105. }
  106.  
  107. </script>
  108.  
  109. <form name="myForm">
  110. <select name="gender" onChange="ajaxFunction(); ">
  111. <option >Select gender</option>
  112. <option>Male</option>
  113.  
  114.  
  115. <option>Female</option>
  116.  
  117. </select>
  118.  
  119.  
  120.  
  121. <div id="theResponse">
  122.  
  123. </div>
  124. </form></body>
  125. </html>

but in getAllGender.jsp
u hv to get the data from the datebase
now it is up to u
i gave u the hint
no much time for me dear
i hope this is very benicifial for u
Last edited by peter_budo; Apr 24th, 2009 at 8:43 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,400
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 502
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: Passing variable value from javascript to jsp page at run time

 
-1
  #6
Apr 24th, 2009
  1. Is there any problem between you and use of code tags that are required by this forum?
  2. If you took time to read previous replies you found find that
    • Post is old and revoked by somebody who just seek quick solution to his school assignment or plunge the hole in what ever he told his employer about his experiences and knowledge
    • Use of Ajax was mentioned, but considered as of topic or different point of implementation in this scenario, therefore not discussed
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 30674 | Replies: 5
Thread Tools Search this Thread



Tag cloud for JSP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC