1

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>
5
  • We need to see the related HTML. Commented Jun 6, 2016 at 17:13
  • <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> Commented Jun 6, 2016 at 17:14
  • is the missing > on the closing table tag a typo? Commented Jun 6, 2016 at 17:17
  • yes, it is just a typo. Commented Jun 6, 2016 at 17:19
  • 1
    You need to use the element identifier. In jQuery you need to use either "." for class or "#" for ids. So you should start your function off with $('#add_gowns').click(function(){ /**/ }); Commented Jun 6, 2016 at 17:21

1 Answer 1

2

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>');
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.