<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<div class="page">
<ul>
<li>Cubic Yards<span><input type="text" name="Quantity" value="" class="quantity"></span></li>
<li>Price <span><input type="text" name="Price" value="25.50" class="price"></span></li>
<li> Total <span><input type="text" name="Total" value="0.00" class="total"></span></li>
</ul>
<div id="foo"></div>
<input type="submit" value="ADD MORE" class="button" id="click">
<ul>
<li>Total Cubic Yards:<input id="cubicYards" type="text" name="cubicYards" value="0"></li>
<li>Total Price:<input id="amount" type="text" name="totalPrice" value="0.00"></li>
</ul>
<input type="button" id="calculate" value="Calculate"/>
<script src="https://code.jquery.com/jquery-2.2.4.js"></script>
</div>
</body>
</html>
// add fields
$( "#click" ).click(function() {
$( "#foo" ).append(
'<ul>' + '\n\r' +
'<li>Cubic Yards <span><input type="text" name="Quantity" value="" class="quantity"></span></li>' + '\n\r' +
'<li>Price <span><input type="text" name="Price" value="" class="price"></span></li>' + '\n\r' +
'<li>Total <span><input type="text" name="Total" value="0.00" class="total"></span></li>' + '\n\r' +
'</ul>'
);
});
$('#calculate').click(function() {
calculateQuantity();
});
// function
function calculateQuantity() {
var sum = 0;
$(".quantity").each(function() {
var q = parseFloat($(this).val());
if(!isNaN(q)) {
$(this).val(q.toFixed(2));
sum += q;
}
});
$('#cubicYards').val(sum.toFixed(2));
};
Output
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |