Reputation: 495
I have one JSP page which consists of three forms and each form consist a drop downlist.
On the first drop downlist onchange
event is called and gets data from the database and save the data into another dropdown list. My problem is when the page reloads the data choosen in the dropdownlist is changed.
How can I solve the problem that the data is not changed when the page load?
Upvotes: 0
Views: 1288
Reputation: 1517
AJAX part is here:
Enclose your contents in 3 separate divs. Now, call reloadReqdForm() function, instead of submitting the page. something.do is the name of Action you are using. Now, whatever will be the result it will come as req.responseText in the last function, which u will put in message var. div1 is the e name/id of the div that u want to reload.
function reloadReqdForm(){
var url = "something.do?queryString";
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
} else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
}
req.open("POST", url, true);
req.onreadystatechange = callbackReloadForm;
req.send(null);
}
function callbackReloadForm()
{
if (req.readyState == 4)
{
if (req.status == 200) {
drawResponse();
}
}
}
function drawResponse() {
var message = req.responseText;
document.getElementById("div1").innerHTML=message;
}
Hope, it will work.
Upvotes: 1
Reputation: 1517
one solution is use AJAX. Another is submit the values of dropdown that u want to preserve & get those vales back from controller by setting them in model object.
Upvotes: 0
Reputation: 16143
How about using JQuery One method which makes the handler execute only once.
$('something').one('onChange', function(e) {
alert('You will only see this once.');
});
Upvotes: 0