Jump to content

Read Text from listbox?


A JM

Recommended Posts

Do you mean...

 

<SELECT>
<option value="somevalue">sometext</option>
</SELECT>

 

Oddly enough, I have something that allows you to switch stuff :-D Made it myself. Just give your select an id and change it for the script. Then, when the form is submitted, just have it switch the text and values and then let the form submit.

 

function shownamval() {
var selection = document.getElementById('mySelect');
var selectedIndex = selection.selectedIndex;
for (i=0;i<selection.length;i++)
{
var names = selection.options[i].innerHTML;
var values = selection.options[i].value;
selection.options[i].innerHTML = values;
selection.options[i].value = names;
}
}

 

If you only want the selected option to have the text/value switched, only:

function shownamval() {
var selection = document.getElementById('mySelect');
var selectedIndex = selection.selectedIndex;
var names = selection.options[selectedIndex].innerHTML;
var values = selection.options[selectedIndex].value;
selection.options[selectedIndex].innerHTML = values;
selection.options[selectedIndex].value = names;
}

 

Oddly enough, I have something that allows you to switch stuff :-D Made it myself. Just give your select an id and change it for the script. Then, when the form is submitted, just have it switch the text and values and then let the form submit.

 

What is the point of that. If you want the "text" of the select field, then just make the value the same as the text. Trying to manipulate the values on submission is completely unnecessary and would fail for anyone without javascript enabled

Oddly enough, I have something that allows you to switch stuff :-D Made it myself. Just give your select an id and change it for the script. Then, when the form is submitted, just have it switch the text and values and then let the form submit.

 

What is the point of that. If you want the "text" of the select field, then just make the value the same as the text. Trying to manipulate the values on submission is completely unnecessary and would fail for anyone without javascript enabled

 

I understand that, but I don't know exactly what he is doing (perhaps he cannot manipulate the values, but merely the text) so I just provide the poster with a way that will help him do what he wants instead of forcing him down the one path.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.