ixnayz Posted September 17, 2014 Share Posted September 17, 2014 Hi, I'm coding a page that starts with a select list loaded from a database and I want to make a different query depending on the item selected, I have been searching around and I can't find a php version of the selectedIndex of a listbox in javascript, any idea? thanks. Quote Link to comment https://forums.phpfreaks.com/topic/291136-basic-how-to-find-out-the-selected-item-of-a-listbox/ Share on other sites More sharing options...
requinix Posted September 17, 2014 Share Posted September 17, 2014 (edited) First thing you should do is stop trying to think of it in terms of things work with .NET and learn from scratch how it works with PHP. There is no SelectedIndex or anything like that. In $_GET or $_POST (depending which you're using) will be an item corresponding to the name of the you used. The value of that item will be the selected value from the . <form method="post"> <select name="dropdown"> <option value="1">One</option> <option value="2">Two</option> <option value="3">Three</option> </select> </form> echo $_POST["dropdown"]; // 1, 2, or 3[edit] You also mentioned Javascript, but it sounded like a PHP question. The Javascript version is, without a framework, just .value on the select element. alert(document.forms[0].dropdown.value); Edited September 17, 2014 by requinix Quote Link to comment https://forums.phpfreaks.com/topic/291136-basic-how-to-find-out-the-selected-item-of-a-listbox/#findComment-1491453 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.