Skip to content

Instantly share code, notes, and snippets.

@jackmaney
Created December 4, 2012 22:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jackmaney/4209323 to your computer and use it in GitHub Desktop.
Save jackmaney/4209323 to your computer and use it in GitHub Desktop.
jQuery fiddling: Grabbing the option that was selected in a <select>
<!doctype html>
<html>
<head>
<title>test</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(
function() {
$("#clicky").click(function(evt) {
evt.preventDefault();
var value = $("#sel").find(":selected").text();
$("#result").text(value); });
});
</script>
</head>
<select id="sel">
<option>One</option>
<option>Two</option>
<option>Three</option>
</select>
<input type="button" id="clicky" value="Clicky!">
<div id="result"></div>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment