0

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
  • 1
    If you want to really learn this, don't use jQuery or any other js lib. Making a simple ajax wrapper is not hard. Go to W3schools site and read a bit on ajax
    – AntonioCS
    Nov 27, 2009 at 23:42

2 Answers 2

1

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

0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.