Reputation: 15
I am new to PHP/JQuery/Bootstrap, but am in the early stages of making an online delivery website for my bricks and mortar business. I have created a fiddle to demonstrate my problem here: https://jsfiddle.net/dLukvqyd/
The checkboxes were working fine, I could click away until my heart was content. Then I introduced jQuery etc to achieve collapsable divs and that's where it all went wrong.
The salt and vinegar checkboxes are working ok, but the toppings checkboxes that appear when the customise button is pressed do not work any longer. The currently checked boxes have been already manually checked in the database as test data.
When I remove the js references, these checkboxes are clickable again.
Any ideas?
I have searched around a lot, but any problem people have with checkboxes and jQuery seem to be when they want to use jQuery to check a box. Whereas I just want to be able to click them with the mouse.
Thank you.
<body>
<a href="shopAMSDNA201A.php">Back to menu</a><br/>
<a href="checkout.php">Checkout</a><br/><span id="basketcount">2 `items</span><br/><span id="baskettotal">£6.90</span><br/><div class="divtable"><div class="divtablerow"><div class="divtableheader divtablecell">Item</div><div class="divtableheader divtablecell">Price</div><div class="divtableheader divtablecell">Salt</div><div class="divtableheader divtablecell">Vinegar</div></div><div class="divtablerow"><div class="divtablecell">1/2lb Beef Burger</div><div class="divtablecell" id="productprice127">£5.15</div><div class="divtablecell"><input type="checkbox" name="salt" onclick="updateSaltVinegar('salt',this,488)"/></div><div class="divtablecell"><input type="checkbox" name="vinegar" onclick="updateSaltVinegar('vinegar',this,488)"/></div><div class="divtablecell" id="488"><button data-toggle="collapse" data-target="#customise488">Customise</button></div></div><div class="collapse" data-toggle="collapse" id="customise488"><div class="divtablerow"><div class="divtablecell" ><strong>Choose your toppings</strong></div></div><div class="divtablerow"><div class="divtablecell" ><input type="checkbox" class="freetoppings" name="multinote" onchange="updateMulti('multinoteID',68,this,488,'0',127)" /> 1-Tomato</div></div><div class="divtablerow"><div class="divtablecell" ><input type="checkbox" class="freetoppings" name="multinote" onchange="updateMulti('multinoteID',69,this,488,'0',127)" checked /> 1-Lettuce</div></div><div class="divtablerow"><div class="divtablecell" ><input type="checkbox" class="freetoppings" name="multinote" onchange="updateMulti('multinoteID',70,this,488,'0',127)" /> 1-Raw Onion</div></div><div class="divtablerow"><div class="divtablecell" ><input type="checkbox" class="freetoppings" name="multinote" onchange="updateMulti('multinoteID',71,this,488,'0',127)" /> 1-Fried Onion</div></div><div class="divtablerow"><div class="divtablecell" ><input type="checkbox" class="freetoppings" name="multinote" onchange="updateMulti('multinoteID',72,this,488,'0',127)" /> Thousand Island</div></div><div class="divtablerow"><div class="divtablecell" ><input type="checkbox" class="freetoppings" name="multinote" onchange="updateMulti('multinoteID',73,this,488,'0',127)" /> Mayo</div></div><div class="divtablerow"><div class="divtablecell" ><input type="checkbox" class="freetoppings" name="multinote" onchange="updateMulti('multinoteID',74,this,488,'0',127)" /> Garlic</div></div><div class="divtablerow"><div class="divtablecell" ><input type="checkbox" class="freetoppings" name="multinote" onchange="updateMulti('multinoteID',75,this,488,'0',127)" /> Sweet Chilli</div></div><div class="divtablerow"><div class="divtablecell" ><input type="checkbox" class="freetoppings" name="multinote" onchange="updateMulti('multinoteID',76,this,488,'0',127)" /> Taco</div></div><div class="divtablerow"><div class="divtablecell" ><input type="checkbox" class="freetoppings" name="multinote" onchange="updateMulti('multinoteID',77,this,488,'0',127)" /> Ketchup</div></div><div class="divtablerow"><div class="divtablecell" ><input type="checkbox" class="freetoppings" name="multinote" onchange="updateMulti('multinoteID',78,this,488,'0',127)" /> Brown Sauce</div></div><div class="divtablerow"><div class="divtablecell" ><input type="checkbox" class="freetoppings" name="multinote" onchange="updateMulti('multinoteID',79,this,488,'0',127)" /> BBQ</div></div><div class="divtablerow"><div class="divtablecell" ><input type="checkbox" class="freetoppings" name="multinote" onchange="updateMulti('multinoteID',80,this,488,'0',127)" /> Pepper</div></div><div class="divtablerow"><div class="divtablecell" ><input type="checkbox" class="freetoppings" name="multinote" onchange="updateMulti('multinoteID',81,this,488,'0',127)" /> Buffalo</div></div><div class="divtablerow"><div class="divtablecell" ><input type="checkbox" class="freetoppings" name="multinote" onchange="updateMulti('multinoteID',82,this,488,'0',127)" /> Relish</div></div><div class="divtablerow"><div class="divtablecell" ><input type="checkbox" class="freetoppings" name="multinote" onchange="updateMulti('multinoteID',83,this,488,'0',127)" /> House</div></div><div class="divtablerow"><div class="divtablecell" ><input type="checkbox" class="freetoppings" name="multinote" onchange="updateMulti('multinoteID',84,this,488,'0',127)" /> Kebab</div></div><div class="divtablerow"><div class="divtablecell" ><input type="checkbox" class="freetoppings" name="multinote" onchange="updateMulti('multinoteID',85,this,488,'0',127)" /> Chipotle</div></div><div class="divtablerow"><div class="divtablecell" ><input type="checkbox" class="freetoppings" name="multinote" onchange="updateMulti('multinoteID',86,this,488,'0',127)" /> Mustard</div></div><div class="divtablerow"><div class="divtablecell"><strong>Paid toppings</strong></div></div><div class="divtablerow"><div class="divtablecell"><input type="checkbox" name="multiproduct" id="multiproduct5" onclick="updateMulti('multiplechoiceproductID',5,this,488,0.25,127)" /> Single Onion Ring - £0.25</div></div><div class="divtablerow"><div class="divtablecell"><input type="checkbox" name="multiproduct" id="multiproduct6" onclick="updateMulti('multiplechoiceproductID',6,this,488,0.25,127)" /> Slice of Cheese - £0.25</div></div><div class="divtablerow"><div class="divtablecell"><input type="checkbox" name="multiproduct" id="multiproduct7" onclick="updateMulti('multiplechoiceproductID',7,this,488,0.45,127)" checked /> Mexican Cheese - £0.45</div></div><div class="divtablerow"><div class="divtablecell"><input type="checkbox" name="multiproduct" id="multiproduct8" onclick="updateMulti('multiplechoiceproductID',8,this,488,0.40,127)" /> Pineapple - £0.40</div></div><div class="divtablerow"><div class="divtablecell"><input type="checkbox" name="multiproduct" id="multiproduct9" onclick="updateMulti('multiplechoiceproductID',9,this,488,0.90,127)" /> Slice of Bacon - £0.90</div></div></div><div class="divtablerow"><div class="divtablecell">Cone of chips</div><div class="divtablecell" id="productprice57">£1.75</div><div class="divtablecell"><input type="checkbox" name="salt" onclick="updateSaltVinegar('salt',this,489)"/></div><div class="divtablecell"><input type="checkbox" name="vinegar" onclick="updateSaltVinegar('vinegar',this,489)"/></div><div class="divtablecell" id="489"></div></div></div>`
</body>
===== JS =====
function updateBasket(id,basketID,addremove)
{
var xmlhttp;
var productID = document.getElementById("ID"+id).value;
var productprice = document.getElementById("saleprice"+id).value;
var addremove = addremove;
var vars = "productID="+productID+"&productprice="+productprice+"&basketID="+basketID+"&addremove="+addremove;
// code for IE7+, Firefox, Chrome, Opera, Safari
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
// code for IE6, IE5
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
var a = JSON.parse(xmlhttp.responseText);
if (a.productquantity!=0) {
document.getElementById("productquantity"+productID).innerHTML = a.productquantity;
}
else {
document.getElementById("productquantity"+productID).innerHTML = "";
}
if (a.basketcount==1) {
document.getElementById("basketcount").innerHTML = a.basketcount+" item";
}
else {
document.getElementById("basketcount").innerHTML = a.basketcount+" items";
}
if (a.baskettotal==null) {
document.getElementById("baskettotal").innerHTML = "£0.00";
}
else {
document.getElementById("baskettotal").innerHTML = "£"+a.baskettotal;
}
console.log (xmlhttp.responseText);
}
}
xmlhttp.open("POST","updateBasket.php",true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send(vars);
}
function updateSaltVinegar (column, cb, bpID) {
//alert (column + ": " + cb.checked);
var column = column;
var xmlhttp;
var vars = "column="+column+"&cb="+cb.checked+"&basketproductID="+bpID;
console.log (vars);
// code for IE7+, Firefox, Chrome, Opera, Safari
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
// code for IE6, IE5
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
console.log (xmlhttp.responseText);
}
}
xmlhttp.open("POST","updateSaltVinegar.php",true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send(vars);
}
function updateMulti (column,multiID,cb,bpID,price,pID) {
//alert (column + ": " + cb.checked);
var column = column;
var multiID = multiID;
var price = price;
var pID=pID;
var xmlhttp;
// code for IE7+, Firefox, Chrome, Opera, Safari
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
// code for IE6, IE5
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
if (column=="multiplechoiceproductID") {
var a = JSON.parse(xmlhttp.responseText);
document.getElementById("productprice"+pID).innerHTML = "£"+a.productprice;
document.getElementById("baskettotal").innerHTML = "£"+a.baskettotal;
console.log (xmlhttp.responseText);
}
}
}
var vars = "column="+column+"&multiID="+multiID+"&basketproductID="+bpID+"&price="+price+"&addremove=";
//if cb checked, run add, else run remove
if (cb.checked) {
vars = vars+"add";
}
else {
vars = vars+"remove";
}
vars = vars+"&pID="+pID;
console.log (vars);
xmlhttp.open("POST","updateMulti.php",true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send(vars);
}
===== CSS =====
div {
width: 80%;
}
div.divtable {
display: table;
border: 1px solid green;
table-layout: fixed;
}
div.divtablerow {
display: table-row;
border: 1px solid red;
}
div.divtablecell {
display: table-cell;
border: 1px solid blue;
width: 20%;
}
.divtablecell.divtableheader {
font-weight: bold;
border: 1px solid orange;
}
div.topping {
width: 200px;
height: 30px;
background: #999;
float: left;
margin: 0 2px 2px 0;
text-align: center;
padding-top: 40px;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
div.topping:nth-child(3n+1) {
clear:both;
}
@media all and (max-width: 500px) {
div.topping {
float: none;
}
}
Upvotes: 0
Views: 70
Reputation: 5041
Your HTML format gave me cancer. If you format you code in a nice way it makes everything easier including debugging.
Change <div class="collapse" data-toggle="collapse" id="customise488">
to <div class="collapse" id="customise488">
to fix your checkbox problem.
Mixing HTML and JavaScript markup is a bad practice and makes debugging more difficult. Since you are already including JQuery for Bootstrap I suggest you bind the change
event for your checkbox. Example below.
function updateBasket(id, basketID, addremove) {
var xmlhttp;
var productID = document.getElementById("ID" + id).value;
var productprice = document.getElementById("saleprice" + id).value;
//var addremove = addremove;
var vars = "productID=" + productID + "&productprice=" + productprice + "&basketID=" + basketID + "&addremove=" + addremove;
// code for IE7+, Firefox, Chrome, Opera, Safari
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
}
// code for IE6, IE5
else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
var a = JSON.parse(xmlhttp.responseText);
if (a.productquantity != 0) {
document.getElementById("productquantity" + productID).innerHTML = a.productquantity;
}
else {
document.getElementById("productquantity" + productID).innerHTML = "";
}
if (a.basketcount == 1) {
document.getElementById("basketcount").innerHTML = a.basketcount + " item";
}
else {
document.getElementById("basketcount").innerHTML = a.basketcount + " items";
}
if (a.baskettotal == null) {
document.getElementById("baskettotal").innerHTML = "£0.00";
}
else {
document.getElementById("baskettotal").innerHTML = "£" + a.baskettotal;
}
console.log(xmlhttp.responseText);
}
};
xmlhttp.open("POST", "updateBasket.php", true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send(vars);
}
function updateSaltVinegar(column, cb, bpID) {
//alert (column + ": " + cb.checked);
//var column = column;
var xmlhttp;
var vars = "column=" + column + "&cb=" + cb.checked + "&basketproductID=" + bpID;
console.log(vars);
// code for IE7+, Firefox, Chrome, Opera, Safari
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
}
// code for IE6, IE5
else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
console.log(xmlhttp.responseText);
}
};
xmlhttp.open("POST", "updateSaltVinegar.php", true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send(vars);
}
function updateMulti(event) {
//alert (column + ": " + cb.checked);
var $this = $(this);
var column = $this.attr('data-column');
var multiID = $this.attr('data-multiID');
var bpID = $this.attr('data-bpID');
var price = $this.attr('data-price');
var pID = $this.attr('data-pID');
var xmlhttp;
// code for IE7+, Firefox, Chrome, Opera, Safari
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
}
// code for IE6, IE5
else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
if (column == "multiplechoiceproductID") {
var a = JSON.parse(xmlhttp.responseText);
document.getElementById("productprice" + pID).innerHTML = "£" + a.productprice;
document.getElementById("baskettotal").innerHTML = "£" + a.baskettotal;
console.log(xmlhttp.responseText);
}
}
};
var vars = "column=" + column + "&multiID=" + multiID + "&basketproductID=" + bpID + "&price=" + price + "&addremove=";
//if cb checked, run add, else run remove
if ( $this.is(':checked')) {
vars = vars + "add";
}
else {
vars = vars + "remove";
}
vars = vars + "&pID=" + pID;
console.log(vars);
xmlhttp.open("POST", "updateMulti.php", true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send(vars);
}
$(document).on('change', '[data-multiID]',updateMulti);
div {
width: 80%;
}
div.divtable {
display: table;
border: 1px solid green;
table-layout: fixed;
}
div.divtablerow {
display: table-row;
border: 1px solid red;
}
div.divtablecell {
display: table-cell;
border: 1px solid blue;
width: 20%;
}
.divtablecell.divtableheader {
font-weight: bold;
border: 1px solid orange;
}
div.topping {
width: 200px;
height: 30px;
background: #999;
float: left;
margin: 0 2px 2px 0;
text-align: center;
padding-top: 40px;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
div.topping:nth-child(3n+1) {
clear: both;
}
@media all and (max-width: 500px) {
div.topping {
float: none;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"
type="text/css"/>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<a href="shopAMSDNA201A.php">Back to menu</a><br/>
<a href="checkout.php">Checkout</a><br/><span id="basketcount">2 items</span><br/><span
id="baskettotal">£6.90</span><br/>
<div class="divtable">
<div class="divtablerow">
<div class="divtableheader divtablecell">Item</div>
<div class="divtableheader divtablecell">Price</div>
<div class="divtableheader divtablecell">Salt</div>
<div class="divtableheader divtablecell">Vinegar</div>
</div>
<div class="divtablerow">
<div class="divtablecell">1/2lb Beef Burger</div>
<div class="divtablecell" id="productprice127">£5.15</div>
<div class="divtablecell"><input type="checkbox" name="salt" onclick="updateSaltVinegar('salt',this,488)"/>
</div>
<div class="divtablecell"><input type="checkbox" name="vinegar"
onclick="updateSaltVinegar('vinegar',this,488)"/></div>
<div class="divtablecell" id="488">
<button data-toggle="collapse" data-target="#customise488">Customise</button>
</div>
</div>
<div class="collapse" id="customise488">
<div class="divtablerow">
<div class="divtablecell"><strong>Choose your toppings</strong></div>
</div>
<div class="divtablerow">
<div class="divtablecell">
<input type="checkbox" class="freetoppings" name="multinote"
data-column="multinoteID" data-multiID="68" data-bpID="488" data-price="0"
data-pID="127"/> 1-Tomato
</div>
</div>
<div class="divtablerow">
<div class="divtablecell"><input type="checkbox" class="freetoppings" name="multinote"
data-column="'multinoteID'" data-multiID="69" data-bpID="488"
data-price="'0'" data-pID="127" checked/>
1-Lettuce
</div>
</div>
<div class="divtablerow">
<div class="divtablecell"><input type="checkbox" class="freetoppings" name="multinote"
data-column="'multinoteID'" data-multiID="70" data-bpID="488"
data-price="'0'" data-pID="127"/> 1-Raw Onion
</div>
</div>
<div class="divtablerow">
<div class="divtablecell"><input type="checkbox" class="freetoppings" name="multinote"
data-column="'multinoteID'" data-multiID="71" data-bpID="488"
data-price="'0'" data-pID="127"/> 1-Fried Onion
</div>
</div>
<div class="divtablerow">
<div class="divtablecell"><input type="checkbox" class="freetoppings" name="multinote"
data-column="'multinoteID'" data-multiID="72" data-bpID="488"
data-price="'0'" data-pID="127"/> Thousand Island
</div>
</div>
<div class="divtablerow">
<div class="divtablecell"><input type="checkbox" class="freetoppings" name="multinote"
data-column="'multinoteID'" data-multiID="73" data-bpID="488"
data-price="'0'" data-pID="127"/> Mayo
</div>
</div>
<div class="divtablerow">
<div class="divtablecell"><input type="checkbox" class="freetoppings" name="multinote"
data-column="'multinoteID'" data-multiID="74" data-bpID="488"
data-price="'0'" data-pID="127"/> Garlic
</div>
</div>
<div class="divtablerow">
<div class="divtablecell"><input type="checkbox" class="freetoppings" name="multinote"
data-column="'multinoteID'" data-multiID="75" data-bpID="488"
data-price="'0'" data-pID="127"/> Sweet Chilli
</div>
</div>
<div class="divtablerow">
<div class="divtablecell"><input type="checkbox" class="freetoppings" name="multinote"
data-column="'multinoteID'" data-multiID="76" data-bpID="488"
data-price="'0'" data-pID="127"/> Taco
</div>
</div>
<div class="divtablerow">
<div class="divtablecell"><input type="checkbox" class="freetoppings" name="multinote"
data-column="'multinoteID'" data-multiID="77" data-bpID="488"
data-price="'0'" data-pID="127"/> Ketchup
</div>
</div>
<div class="divtablerow">
<div class="divtablecell"><input type="checkbox" class="freetoppings" name="multinote"
data-column="'multinoteID'" data-multiID="78" data-bpID="488"
data-price="'0'" data-pID="127"/> Brown Sauce
</div>
</div>
<div class="divtablerow">
<div class="divtablecell"><input type="checkbox" class="freetoppings" name="multinote"
data-column="'multinoteID'" data-multiID="79" data-bpID="488"
data-price="'0'" data-pID="127"/> BBQ
</div>
</div>
<div class="divtablerow">
<div class="divtablecell"><input type="checkbox" class="freetoppings" name="multinote"
data-column="'multinoteID'" data-multiID="80" data-bpID="488"
data-price="'0'" data-pID="127"/> Pepper
</div>
</div>
<div class="divtablerow">
<div class="divtablecell"><input type="checkbox" class="freetoppings" name="multinote"
data-column="'multinoteID'" data-multiID="81" data-bpID="488"
data-price="'0'" data-pID="127"/> Buffalo
</div>
</div>
<div class="divtablerow">
<div class="divtablecell"><input type="checkbox" class="freetoppings" name="multinote"
data-column="'multinoteID'" data-multiID="82" data-bpID="488"
data-price="'0'" data-pID="127"/> Relish
</div>
</div>
<div class="divtablerow">
<div class="divtablecell"><input type="checkbox" class="freetoppings" name="multinote"
data-column="'multinoteID'" data-multiID="83" data-bpID="488"
data-price="'0'" data-pID="127"/> House
</div>
</div>
<div class="divtablerow">
<div class="divtablecell"><input type="checkbox" class="freetoppings" name="multinote"
data-column="'multinoteID'" data-multiID="84" data-bpID="488"
data-price="'0'" data-pID="127"/> Kebab
</div>
</div>
<div class="divtablerow">
<div class="divtablecell"><input type="checkbox" class="freetoppings" name="multinote"
data-column="'multinoteID'" data-multiID="85" data-bpID="488"
data-price="'0'" data-pID="127"/> Chipotle
</div>
</div>
<div class="divtablerow">
<div class="divtablecell"><input type="checkbox" class="freetoppings" name="multinote"
data-column="'multinoteID'" data-multiID="86" data-bpID="488"
data-price="'0'" data-pID="127"/> Mustard
</div>
</div>
<div class="divtablerow">
<div class="divtablecell"><strong>Paid toppings</strong></div>
</div>
<div class="divtablerow">
<div class="divtablecell"><input type="checkbox" name="multiproduct" id="multiproduct5"
data-column="'multiplechoiceproductID'" data-multiID="5"
data-bpID="488" data-price="0.25" data-pID="127"/>
Single Onion Ring - £0.25
</div>
</div>
<div class="divtablerow">
<div class="divtablecell"><input type="checkbox" name="multiproduct" id="multiproduct6"
data-column="'multiplechoiceproductID'" data-multiID="6"
data-bpID="488" data-price="0.25" data-pID="127"/>
Slice of Cheese - £0.25
</div>
</div>
<div class="divtablerow">
<div class="divtablecell"><input type="checkbox" name="multiproduct" id="multiproduct7"
data-column="'multiplechoiceproductID'" data-multiID="7"
data-bpID="488" data-price="0.45" data-pID="127"
checked/> Mexican Cheese - £0.45
</div>
</div>
<div class="divtablerow">
<div class="divtablecell"><input type="checkbox" name="multiproduct" id="multiproduct8"
data-column="'multiplechoiceproductID'" data-multiID="8"
data-bpID="488" data-price="0.40" data-pID="127"/>
Pineapple - £0.40
</div>
</div>
<div class="divtablerow">
<div class="divtablecell"><input type="checkbox" name="multiproduct" id="multiproduct9"
data-column="'multiplechoiceproductID'" data-multiID="9"
data-bpID="488" data-price="0.90" data-pID="127"/>
Slice of Bacon - £0.90
</div>
</div>
</div>
<div class="divtablerow">
<div class="divtablecell">Cone of chips</div>
<div class="divtablecell" id="productprice57">£1.75</div>
<div class="divtablecell"><input type="checkbox" name="salt" onclick="updateSaltVinegar('salt',this,489)"/>
</div>
<div class="divtablecell"><input type="checkbox" name="vinegar"
onclick="updateSaltVinegar('vinegar',this,489)"/></div>
<div class="divtablecell" id="489"></div>
</div>
</div>
EDIT 1
https://api.jquery.com/change/ Please see the JQuery docs for more information.
This line makes JQuery listen for the change event for all elements that have a data-multiID
attribute. When one of those elements fires a change event then the function updateMulti
handles the event. The only argument passed to the change event handler (updateMulti) is an event
object.
$(document).on('change', '[data-multiID]',updateMulti);
Inside the event handler this
references the object that fired the event.
So $this
is a JQuery object for the checkbox that was changed.
var $this = $(this);
If you look back to the HTML markup each checkbox had data attributes. The lines below assign those data attributes to variable from the changed checkbox. So no, you do not need to pass the other arguments to the event handler.
var column = $this.attr('data-column');
var multiID = $this.attr('data-multiID');
var bpID = $this.attr('data-bpID');
var price = $this.attr('data-price');
var pID = $this.attr('data-pID');
Upvotes: 1