Two Laptop Bag*
The moose likes JSP and the fly likes How to retain selected content after post on same page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "How to retain selected content after post on same page" Watch "How to retain selected content after post on same page" New topic
Author

How to retain selected content after post on same page

chetan sisodiya
Greenhorn

Joined: Nov 14, 2011
Posts: 12
Hi Geeks,

I m very new to JSP and java script.
I have a 2 dropdown list. In both drop down i m fetching some data from data base.
In SECOND DROPDOWN LIST I have to fetch data depending on the selected item of the SECOND DropDOwn list. I have succeeded in that.

PROBLEM :
But when I select an item in first dropdown list, i m posting fors data to jsp code,and proper resuld are reflecting back. But on every ONCHANGE event on my first dropdown list page is getting reloaded and the FIRST DROPDOWN list data is get emptied. I mean it should contain what I have selected after posting parameter to jsp.
How can I stop from this or how can i retain value in the dropdown list. Is should get set back to default....
Miku Ranjan
Ranch Hand

Joined: Oct 11, 2011
Posts: 98
hi,
Use ajax call to populate your select box .
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60802
    
  65

Exactly. "Cascading dropdowns" has become almost a poster child for Ajax.

If the idea of Ajax scares you, then adopting a library such as jQuery makes it a single line of script. If this direction intrigues you, I can point you to free downloadable examples from my jQuery book.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
himanshu.harish agrawal
Ranch Hand

Joined: Oct 18, 2010
Posts: 47

Before heading towards big daddies like Ajax and jQuery, try visiting . I think you get you solution.

Regards,
Himanshu
chetan sisodiya
Greenhorn

Joined: Nov 14, 2011
Posts: 12

posted Today 1:49:17 PM 0
uday singh rajpurohit wrote:
Thanks Himanshu


Himanshu, the link you gave is I m familior with already. My problem is that I am not senting parameter to a diff page. I m posting dropdown's parameter on the same page. and on eveny ONCHANGE event on the first dropdown list proper result are reflectiung back on second parameter but the value of second drop down is set set back to default selected calue.. Is should be what I selected before.



Can any once plese send the code to populate the value in drodown list after submitting form.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to retain selected content after post on same page
 
Similar Threads
drop down box using struts
Retain selected content in a JSP
JSP and Dropdown Box
retain selected dropdown value in the next page
calling function while re postingthe same page..javascript