Skip to content

Instantly share code, notes, and snippets.

@jhnwllr
Last active August 15, 2018 17:38
Show Gist options
  • Save jhnwllr/065366b8fef2947449e43a571143bc70 to your computer and use it in GitHub Desktop.
Save jhnwllr/065366b8fef2947449e43a571143bc70 to your computer and use it in GitHub Desktop.
fresh block
license: mit
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>val demo</title>
<style>
p {
color: red;
margin: 4px;
}
b {
color: blue;
}
</style>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<p></p>
<select id="multiple" multiple="multiple">
<option selected="selected">Multiple</option>
<option>Multiple2</option>
<option selected="selected">Multiple3</option>
</select>
<script>
function displayVals() {
var multipleValues = $( "#multiple" ).val() || [];
$( "p" ).html(" <b>Multiple:</b> " + multipleValues.join( ", " ) );
}
$( "select" ).change( displayVals );
displayVals();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment