Fetching the selected value of a 'select' element in JavaScript.

label Programming
account_circle Unassigned
schedule 3 Days
account_balance_wallet $5

I'm currently trying to fetch a value from a 'select' element using JavaScript/JQuery, but for some reason I'm encountering some errors, so I'm obviously not doing it right!

<select id="obejectlistid">

<option selectedID="square">Square </option>

<option selectedID="circle">Circle</option>

<option selectedID="triangle">Triangle</option>

</select>


This is the HTML code I'm using, and the JavaScript code is below. I'm wondering if there's any way to fetch the selected value in a select element (drop down list) using JavaScript/JQuery?

function onAddNewShape() {

var object_list = document.getElementById("objectlist");

var shape = object_list.options[object_list.selectedIndex].value;

alert(shape);

}


Nov 30th, -0001
Hi here is the working solution for you.

<html>
<head>
<script type="text/javascript">
function onAddNewShape() {


var get_id = document.getElementById("objectlist");
var result = get_id.options[get_id.selectedIndex].value;
alert(result);
}
</script>
</head>
<body>
<select id="objectlist" onchange="onAddNewShape

()">
<option selectedID="square">Square </option>
<option selectedID="circle">Circle</option>
<option selectedID="triangle">Triangle</option>
</select>
</body>
</html>
Jun 28th, 2013

Studypool's Notebank makes it easy to buy and sell old notes, study guides, reviews, etc.
Click to visit
The Notebank
...
Nov 30th, -0001
...
Nov 30th, -0001
Jun 25th, 2017
check_circle
Mark as Final Answer
check_circle
Unmark as Final Answer
check_circle
Final Answer

Secure Information

Content will be erased after question is completed.

check_circle
Final Answer