View Full Version : GET selectedIndex number
01-07-2010, 09:16 PM
I'm in need of passing the selectedIndex number of a select menu from a form to a PHP page. I can pass the actual value of the select menu using:
$State = $_POST['State'];
How would I get the selectedIndex number?
01-07-2010, 09:23 PM
01-07-2010, 09:41 PM
01-07-2010, 09:42 PM
Create a hidden input in your form. Give it an id and a name. Then use onchange in your select menu and set the value of that hidden input using document.getElementById('yourinput').value = this.selectedIndex;
01-08-2010, 10:31 AM
You may store all the options and indexes as a PHP associative array and then get the key from the dropdown value using array_search() (http://php.net/array_search)
Powered by vBulletin® Version 4.2.2 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.