DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   JSP (http://www.daniweb.com/forums/forum24.html)
-   -   Passing variable value from javascript to jsp page at run time (http://www.daniweb.com/forums/thread55227.html)

vijaysdon Sep 16th, 2006 10:22 am
Passing variable value from javascript to jsp page at run time
 
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,...)

masijade Sep 16th, 2006 3:58 pm
Re: Passing variable value from javascript to jsp page at run time
 
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.

ukbasak Apr 23rd, 2009 8:13 am
Re: Passing variable value from javascript to jsp page at run time
 
Request all developer to send codes....

Thanks in advance

masijade Apr 23rd, 2009 8:24 am
Re: Passing variable value from javascript to jsp page at run time
 
Quote:

Originally Posted by ukbasak (Post 853032)
Request all developer to send codes....

Thanks in advance

What a maroon.

amarjeetsingh Apr 24th, 2009 7:58 am
Re: Passing variable value from javascript to jsp page at run time
 
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

peter_budo Apr 24th, 2009 8:50 am
Re: Passing variable value from javascript to jsp page at run time
 
  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


All times are GMT -4. The time now is 4:34 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC