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
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:
- how can I check when the last list item has been deleted?Best solution by SharePoint
- How to execute ajax script on Jquery mobile?Best solution by Stack Overflow
- How to execute Unix shell script from Windows?Best solution by Stack Overflow
- How to programatically select a item in list using c#?Best solution by Software Quality Assurance & Testing
- How do I find the item number on a ebay item?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
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.