<html>
<head>
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<meta charset=utf-8 />
<title>Position Trail</title>
<script type="text/javascript">
function constructJSON()
{
var myArray = {};
myArray[0] = createArray('apple');
myArray[1] = createArray('Mango');
myArray[2] = createArray('Pineapple');
myArray[3] = createArray('Grape');
console.dir(myArray);
$("#a").html(JSON.stringify(myArray));
/*
var obj = $("#myform").serializeArray();
$("#a").html(JSON.stringify(obj));*/
}
function createArray(name){
var data = new Object();
var innerArray = [];
var arrayCount = 0;
var el = "input[data-gpname='"+name+"']";
$el = $(el);
$.each($el, function(i, item){
data = {};
if(item.checked){
data.name = $(item).val();
data.price = $(item).attr("data-price");
innerArray[arrayCount] = data;
arrayCount++;
}
});
return innerArray;
}
</script>
</head>
<body>
<form method="post" id="myform">
Apple
<input type="radio" onclick="constructJSON()" id="one" name="apple" data-gpname="apple" data-price="10" value="light"/> Light
<input type="radio" onclick="constructJSON()" id="two" name="apple" data-gpname="apple" data-price="20" value="dark" /> Dark
<input type="radio" onclick="constructJSON()" id="one1" name="apple1" data-gpname="apple" data-price="120" value="light2"/> Light11
<input type="radio" onclick="constructJSON()" id="two1" name="apple1" data-gpname="apple" data-price="210" value="dark1" /> Dark22
<input type="text" id="appleqty" name="appleqty" value="" />
<br>
Mango
<input type="radio" onclick="constructJSON()" id="three" name="Mango" data-gpname="Mango" data-price="30" value="light"/> Light
<input type="radio" onclick="constructJSON()" id="one" name="Mango" data-gpname="Mango" data-price="40" value="dark" /> Dark
<input type="text" id="Mangoqty" name="Mangoqty" value="" />
<br>
Pine Apple
<input type="radio" onclick="constructJSON()" id="four" name="Pineapple" data-gpname="Pineapple" data-price="50" value="light"/> Light
<input type="radio" onclick="constructJSON()" id="five" name="Pineapple" data-gpname="Pineapple" data-price="60" value="dark" /> Dark
<input type="text" id="Pineappleqty" name="Pineappleqty" value="" />
<br>
Grape
<input type="radio" onclick="constructJSON()" id="six" name="Grape" data-gpname="Grape" data-price="70" value="light"/> Light
<input type="radio" onclick="constructJSON()" id="seven" name="Grape" data-gpname="Grape" data-price="80" value="dark" /> Dark
<input type="text" id="Pineappleqty" name="Pineappleqty" value="" />
<textarea name="a" id="a" cols="50"></textarea>
<input type="submit" name="se" value="se" />
</form>
</body>
</html>
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. |