I want to populate a DropDown control on page load using AJAX. I have the code and it is working, but I am not following as to which event to use.
A:
Firstly, what does the ajax callback return? Partial html formatted as json/xml, or straight up HTML?
One way would be to just re-build the select element and iterate and append option elements, then use the replaceWith
method to replace the dropdown. If you have an event on the dropdown, you may need to use liveQuery in order for it to "stick". It would help seeing the code you currently have in order for a definitive answer.
meder
2009-11-22 09:16:55
Doesn't he ask for the event on which attach his code?
Eineki
2009-11-22 09:21:35
+1
A:
I'm assuming you're not using a JavaScript framework, but this is simple with jQuery.
$(document).ready(function(){
$("#some_div").load("/dropdown.html", function(){
[any additional code to make it work]
});
});
I hope I'm understanding your question correctly.
Greg
2009-11-22 09:53:14
Can this code be just pasted on the HTML form or anything else is needed? I am not aware of JQuery.
RPK
2009-11-22 11:09:45
This code would go between your <script> tags, just like any javascript. In a word, what it does is (1) waits for the HTML document to be loaded (2) fetches a page with AJAX and puts into an element with id "some_div" in this case (3) optionally executes some more javascript to make further use of the page that it just fetched when THAT page is loaded. This is called chaining. I suggest you google for an introductory tutorial to jquery. It's not hard to learn and it makes things like this a lot simpler
Greg
2009-11-22 16:30:23