| | |
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,...)
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.
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
----------------------------------------------
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
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
----------------------------------------------
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
•
•
Join Date: Feb 2009
Posts: 21
Reputation:
Solved Threads: 1
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
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
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 Syntax (Toggle Plain Text)
<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
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.
- Is there any problem between you and use of code tags that are required by this forum?
- 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
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
![]() |
Similar Threads
- install and run tomcat3 and implement a simple jsp page (JSP)
- Very Very Urgent...Need Code for Calculating Execution Time For Jsp Page (JSP)
- How to run iReport jrxml from a jsp page (JSP)
- Generating clientside javascript (ASP)
- I want to run my jsp page online on internet (Java)
- how to call javabean from jsp page upon onChange event (JSP)
- Passing paramter from javascript to jsp (JavaScript / DHTML / AJAX)
Other Threads in the JSP Forum
- Previous Thread: creating installer for java web application
- Next Thread: GZIP in Struts
Views: 30674 | Replies: 5
| Thread Tools | Search this Thread |
Tag cloud for JSP
action apache array backbutton books boonex combobox comma connection csv database debugging development directorystructure dropdownlist dynamicpagetitles eclipse examples excel form forward frames generating glassfish ie8 image2database imagestoring imagetodatabase imageupload integer internet java javaee javascript jsf jsp jsppagetitles levels mime-rfc multiple mvc2 mvcmodel2 mysql netbeans network non-standard-mime objects open parameters passing ping printinserverinsteadofclient project quickguide read redirect request.getparameter resorces response resultset seperated servlet servletdopost()readxml sessions social software source sql ssl standard-mime state_saving_method stocks sun tomcat tutorial unique update values video web write






