RSS Forums RSS

Passing variable value from javascript to jsp page at run time

Please support our JSP advertiser: Programming Forums
Reply
Posts: 4
Reputation: vijaysdon is an unknown quantity at this point 
Solved Threads: 0
vijaysdon's Avatar
vijaysdon vijaysdon is offline Offline
Newbie Poster

Help Passing variable value from javascript to jsp page at run time

  #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,...)
AddThis Social Bookmark Button
Reply With Quote  
Posts: 1,954
Reputation: masijade is a splendid one to behold masijade is a splendid one to behold masijade is a splendid one to behold masijade is a splendid one to behold masijade is a splendid one to behold masijade is a splendid one to behold masijade is a splendid one to behold 
Solved Threads: 198
masijade's Avatar
masijade masijade is offline Offline
Posting Virtuoso

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

  #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  
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

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

Thanks in advance
Reply With Quote  
Posts: 1,954
Reputation: masijade is a splendid one to behold masijade is a splendid one to behold masijade is a splendid one to behold masijade is a splendid one to behold masijade is a splendid one to behold masijade is a splendid one to behold masijade is a splendid one to behold 
Solved Threads: 198
masijade's Avatar
masijade masijade is offline Offline
Posting Virtuoso

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

  #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  
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

  #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 7: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  
Posts: 3,460
Reputation: peter_budo is a splendid one to behold peter_budo is a splendid one to behold peter_budo is a splendid one to behold peter_budo is a splendid one to behold peter_budo is a splendid one to behold peter_budo is a splendid one to behold peter_budo is a splendid one to behold 
Solved Threads: 412
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

  #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, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Views: 23404 | Replies: 5 | Currently Viewing: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 1:13 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC