Created
June 2, 2016 07:59
-
-
Save nonZero/10b65616414deb48e1b0a58c2e93834b to your computer and use it in GitHub Desktop.
simple js order form
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Title</title> | |
</head> | |
<body> | |
<ul id="dishes"> | |
<li data-id="123">asdsadsadada</li> | |
<li data-id="456">asd</li> | |
<li data-id="789">asdsaasddsadada</li> | |
<li data-id="1">asdsads</li> | |
<li data-id="2">asasd</li> | |
</ul> | |
<div style="border: 1px solid black"> | |
<form id="frm"> | |
<ul></ul> | |
<button>Order</button> | |
</form> | |
</div> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script> | |
<script src="order.js"></script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function () { | |
console.log("start"); | |
$('#dishes').on('click', 'li', function () { | |
var el = $(this); | |
console.log(el); | |
var new_el = $('<li>').text(el.text()); | |
new_el.append($('<input type="hidden" name="item">').val(el.data('id'))); | |
$('#frm ul').append(new_el); | |
}); | |
console.log("end"); | |
// requst.POST['item'].getlist() | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment