Jessica Mather Jessica Mather - 4 months ago 6x
jQuery Question

Appending to a list with multiple input values

I am trying to get the values from input boxes and then print them out as a sentence into a list. In theory I feel this should work but don't understand why it is not. please help!

$('add_gowns').click(function() {
var size = document.getElementById("blksize").value;
var colour = document.getElementById("colouroption").value;
var quantity = document.getElementById("gownquantity").value;

$("#content ul li:last").append("<li> Size: "+size+", Colour: "+colour+", Quantity: "+quantity+"</li>");

Here is the related html

<td><input type="number" id="blksize"></td>

<td><select id="colouroption"></select></td>

<td><input type="number" id="gownquantity"></td>
<td><input type="submit" id="add_gowns" value="Add"/></td>

<div id="content">


The following should work as tested:

$('#add_gowns').click(function() {
    var size = $("#blksize").val();
    var colour = $("#colouroption").val();
    var quantity = $("#gownquantity").val();

    $("#content ul").append('<li> Size: ' + size + ', Colour: ' + colour + ', Quantity: ' + quantity + '</li>');