0

Adding the personal touch to pset8 mashup. I want to have a select dropdown list in index.html, and access the selected value in scripts.js If it was a PHP file it would be no problem, but I'm not so comfortable with javascript.

How to set the dropdown list selected value to a variable in scripts.js?

0

to access the value sent to the server through Javascript, you could give this <select> element an id and access the value of the currently selected option as follows:

<!-- HTML -->

<select id="my_menu">
    <option value="1">foo</option>
    <option value="2">bar</option>
</select>
// jQuery
var selectedValue = $('#my_menu').val();

see more!

// plain JavaScript
var selectElement = document.getElementById('my_id');
var selectedValue = selectedElement.options[selectedElement.selectedIndex].value;

see more!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .