Skip to content

Instantly share code, notes, and snippets.

@kingbuzzman
Created August 23, 2011 19:57
Show Gist options
  • Select an option

  • Save kingbuzzman/1166326 to your computer and use it in GitHub Desktop.

Select an option

Save kingbuzzman/1166326 to your computer and use it in GitHub Desktop.
jQuery implementation.. still sucky..
<!DOCTYPE html>
<html>
<head>
<title>Example 2</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.js" type="text/javascript" charset="ISO-8859-1"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#name,#phone,#items").live("change", function(){
var items = $("#items");
var itemLabels = $("#label_items");
var total = 0;
// update labels
$("#label_name").html($("#name").val());
$("#label_phone").html($("#phone").val());
// clear ul
itemLabels.empty();
// append item and increment total
items.children().map(function(index,item){
item = $(item);
if(item.attr("selected")){
total += parseFloat(item.val());
itemLabels.append(
$("<li>").html(item.html())
);
}
});
// update total
$("#label_total").html(total);
});
$("#name,#phone").live("keyup", function(){ $(this).change(); });
});
</script>
</head>
<body>
<div>
<label for="name">Name: </label>
<input name="name" id="name" type="text"><br>
<label for="phone">Phone: </label>
<input name="phone" id="phone" type="text"><br>
<label for="items">Items<label>
<select name="items" id="items" multiple="multiple" size="5">
<option value="5.00">$5.00 Cheese burger</option>
<option value="7.00">$7.00 1lb Cheese burger</option>
<option value="3.00">$3.00 Fries</option>
<option value="2.00">$2.00 Soda</option>
<option value="8.00">$8.00 Cheese burger combo</option>
</select>
</div>
<br><br>
Checkout for <strong id="label_name"></strong><br>
Call: <strong id="label_phone"></strong><br>
Order:<br>
<ul id="label_items"></ul><br>
Total $: <strong id="label_total"></strong>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment