Ravendark Posted November 30, 2010 Share Posted November 30, 2010 Hello, I am searching to find an answer to my question but without success. I have a HTML dropdown list like this: <select name="ports"> <option value="10">1/1/1/0/shdsl</option> <option value="12">1/1/2/0/shdsl</option> <option value="14">1/1/3/0/shdsl</option> <option value="16">1/1/4/0/shdsl</option> <option value="18">1/1/5/0/shdsl</option> <option value="20">1/1/6/0/shdsl</option> <option value="22">1/1/7/0/shdsl</option> <option value="24">1/1/8/0/shdsl</option> <option value="26">1/1/9/0/shdsl</option> <option value="28">1/1/10/0/shdsl</option> <option value="30">1/1/11/0/shdsl</option> <option value="32">1/1/12/0/shdsl</option> <option value="34">1/1/13/0/shdsl</option> <option value="36">1/1/14/0/shdsl</option> <option value="38">1/1/15/0/shdsl</option> <option value="40">1/1/16/0/shdsl</option> <option value="42">1/1/17/0/shdsl</option> <option value="44">1/1/18/0/shdsl</option> <option value="46">1/1/19/0/shdsl</option> <option value="48">1/1/20/0/shdsl</option> <option value="50">1/1/21/0/shdsl</option> <option value="52">1/1/22/0/shdsl</option> <option value="54">1/1/23/0/shdsl</option> <option value="56">1/1/24/0/shdsl</option> </select> All I want to do is to get the value & the text (e.g 56 & "1/1/24/0/shdsl"). I get the value (say 56) with: $_POST['ports'] Could you please help me get the text? Link to comment https://forums.phpfreaks.com/topic/220220-getting-value-text-from-a-dropdown/ Share on other sites More sharing options...
New Coder Posted November 30, 2010 Share Posted November 30, 2010 You need to put the text in the value too: <option value="10 1/1/1/0/shdsl">1/1/1/0/shdsl</option> <option value="12 1/1/2/0/shdsl">1/1/2/0/shdsl</option> etc etc Or you could create a lookup table that references the value. That way you can produce two variables, one with the value eg. 10 and one with the text item eg: 1/1/1/0/shdsl Link to comment https://forums.phpfreaks.com/topic/220220-getting-value-text-from-a-dropdown/#findComment-1141310 Share on other sites More sharing options...
Ravendark Posted November 30, 2010 Author Share Posted November 30, 2010 Nah, won't help, cause I need the 2digit value as it is. I thought of a different way, I use javascript to place the text to a hidden text field, then pass it to php... Thanks though Link to comment https://forums.phpfreaks.com/topic/220220-getting-value-text-from-a-dropdown/#findComment-1141311 Share on other sites More sharing options...
chronister Posted November 30, 2010 Share Posted November 30, 2010 Just to expand on what New Coder said.... The value attribute is what your after and what you use in the scripts... the display text is solely for the user to read. You may be able to use Javascript to get that value (not sure on this), but the php $_POST / $_GET array is going to contain the value attribute of the item selected. This is just the way PHP handles HTML form submissions. If the numbers in the attribute field correspond with an array or a database ID, then you can take that value and grab the data that goes with it. But if your list is hard coded then you need to change the code to reflect the actual value in the value attribute field. Hope this makes sense and does not confuse. Nate Link to comment https://forums.phpfreaks.com/topic/220220-getting-value-text-from-a-dropdown/#findComment-1141312 Share on other sites More sharing options...
chronister Posted November 30, 2010 Share Posted November 30, 2010 Nah, won't help, cause I need the 2digit value as it is. I thought of a different way, I use javascript to place the text to a hidden text field, then pass it to php... Thanks though It may work, but seems to be a longer way around.. and if a user has Javascript turned off, then your form does not work right. It is best to work within the scope of the languages your using. The value attribute is there as the value, the label is the label. Your trying to make the label be the value. If the 2 digit value HAS to remain, then what is that being used for that it cannot retrieve the label that it represents. Just my 2 cents. Nate Link to comment https://forums.phpfreaks.com/topic/220220-getting-value-text-from-a-dropdown/#findComment-1141314 Share on other sites More sharing options...
Ravendark Posted November 30, 2010 Author Share Posted November 30, 2010 Thanks for replying. The 2digit value is a port ifindex which is used to for shut-no shut. The rest is just the interface/port name which is also necessary for informing the user of which port is manipulating. I will just have to add a javacript test (if disabled alert the user) and I guess it will be fine. Thanks for your answers! Link to comment https://forums.phpfreaks.com/topic/220220-getting-value-text-from-a-dropdown/#findComment-1141316 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.