Monday 15 March 2010

javascript - Java Script add value of variable to object property? -



javascript - Java Script add value of variable to object property? -

i'm new here , javascript. have assignment asks "create new property in foodinfo object plus value of toppings variable, , set ne property's value to value of current element in toppingboxes array."

here code have not working, have tried multiple things cant print out toppings on page:

for (var = 0; < toppingboxes.length; i++) { if (toppingboxes[i].checked) { toppings = toppings + 1; foodinfo.topping[toppings] = toppingboxes[i].value; } }

here code assignment gave me print it, code correct, code above need help with:

foodsummary.innerhtml += "<ul>"; (var = 1; < 6; i++) { if (foodinfo["topping" + i]) { foodsummary.innerhtml += "<li>" + foodinfo["topping" + i] + "</li>"; } } foodsummary.innerhtml += "</ul>";

i know code stops running when hits line "foodinfo.topping[toppings] = toppingboxes[i].value;" know wrong. having problem instructions mentioned above...any help working? give thanks in advance!!

try this:

var toppings = 0; (var = 0; < toppingboxes.length; i++) { if (toppingboxes[i].checked) { toppings = toppings + 1; foodinfo['toppings' + toppings] = toppingboxes[i].value; } }

javascript

No comments:

Post a Comment