How to execute a selected statement?

List menu -- How to execute statement when item is selected?

  • In Dreamweaver I have a list box or menu/list. I am dynamically adding data from an array into it, so when the page loads, I have a list-box with names in. This is how it looks <?php echo "<select name="."username"."id="."username".">"; foreach ($user_array as $arr) { echo "<option>$arr</option>"; } echo "</select>"; ?> Now how do I go about making the listbox executesomething when the user selects something in it? Because I have three other textboxes, and when the user selects a name in the list box, I want to put that name he selected into a variable (also don't know how I'm going to do that with a list box) and then search through my database and insert some of the data of that person in the textboxes. So all i need to know is: How to create that on event click event and How to put that selected value then in a variable (inside the event)

  • Answer:

    You can easily execute a javascript function by using something like this: <select name=".$username."id=".$username." onchange='yourfunction()' >

mrbunyrabit at Stack Overflow Visit the source

Was this solution helpful to you?

Other answers

The following php code generated a select field with a dynamic number of options. <?php $user_array = Array("Smith", "John", "Bob", "Jake"); echo "<select name="."username"." id="."username".">"; foreach ($user_array as $arr) { echo "<option>$arr</option>"; } echo "</select>"; ?> The following JavaScript handles change events on the select element. $(document).ready(function() { var username = $('#username'); var selectedValue = null; username.change(function(){ alert(username.val()); selectedValue = username.val(); }); });

Jose Vega

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.