View Single Post
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