Jessica Mather Jessica Mather - 6 months ago 7
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>
</tr>

</table>
<div id="content">
<ul></ul>
</div>

Answer

The following should work as tested: https://jsfiddle.net/z8q7n9gn/

$('#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>');
});