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,...)

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.

Request all developer to send codes....

Thanks in advance

Request all developer to send codes....

Thanks in advance

What a maroon.

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

<html>
<head>






</head>



<body>
<script type="text/javascript">function ajaxFunction()
{var xmlHttp;
try
  {  // Firefox, Opera 8.0+, Safari 
   xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {  // Internet Explorer 
   try
    {    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    }
  catch (e)
    {    try
      {      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      }
    catch (e)
      {      alert("Your browser does not support AJAX!");      return false;      }    }  }
  xmlHttp.onreadystatechange=function()
    {
	   //alert("i m  not  in ready state");
	   
	    if(xmlHttp.readyState==0)
      {
      //document.myForm.time.value=xmlHttp.responseText;
	    alert("The request is not initialized");
	  
	   

	   
	  
      }
	      if(xmlHttp.readyState==1)
      {
      //document.myForm.time.value=xmlHttp.responseText;
	    alert("The request has been set up");
	  
	   

	   
	  
      }
	  
	  
	  
	        if(xmlHttp.readyState==2)
      {
      //document.myForm.time.value=xmlHttp.responseText;
	    alert("The request has been sent");
	  
	   

	   
	  
      }
	  
	  	        if(xmlHttp.readyState==3)
      {
      //document.myForm.time.value=xmlHttp.responseText;
	    alert("The request is in process");
	  
	   

	   
	  
      }
	   
	  
	   
	  
	  
	   
	   
	  
    if(xmlHttp.readyState==4)
      {
      //document.myForm.time.value=xmlHttp.responseText;
	    //alert("i m in ready state");
	  
	   document.getElementById("theResponse").innerHTML = xmlHttp.responseText;

	   
	  
      }
    }
	      var gender=document.myForm.gender.value;
	      var url="getAllGender.jsp";
          url=url+"?gender="+gender+"&sid="+Math.random();
          //url=url+"&sid="+Math.random();

	
	  
         xmlHttp.open("GET",url,true);
         xmlHttp.send(null); 
   }
  
  </script>

  <form name="myForm">
 <select   name="gender"  onChange="ajaxFunction(); ">
<option  >Select gender</option>
<option>Male</option>


<option>Female</option>

</select>



<div id="theResponse">

</div>
</form></body>
</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

  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
commented: Well said +20

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,...)

If you took your time to read answer by masijade you wouldn't have to post this question.

Thread closed.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.