views:

206

answers:

2

I've done some reading on AJAX, and would like to create a listbox, that controls what is displayed in a separate textbox located within the same form. The backend of the website is handled in php, and the possible values and whatnot is stored within the MySQL database via php. What's the best way of obtaining the listbox values as well as the textbox values, and if your answer is JS, how do I create multiple selects in JS?

+1  A: 

Well this is really a wide theme question. My approach would be to create a listbox with php and put an onchange event that will call an ajax with value parameter, that ajax call will fill textbox.

You should use jquery, read some documentation here http://docs.jquery.com/Main_Page

dfilkovi
A: 

multiple select listbox

   <select id="choices" multiple="multiple" .. >

If you were using jQuery you could do something like:

 $("#choices").change(function() {
     var choices = {};
     $("#choices option:selected").each(function() {
         choices[this.id] = $(this).val();
     });
     $.post("http://example.com/choice_handler.php", choices, function(content) {
         $("#textarea").val(content);
     });
 });

choice___handler.php would look at $_POST to retrieve the id/value pairs and produce content that would be returned and then assgned as the value of a textarea.

Note: i haven't tested/debugged any of this - just some code sketching here

Scott Evernden