Graham Slick Graham Slick - 4 months ago 4x
jQuery Question

How to call a variable inside a listener

I'm trying to have displayed each time you click on a button a new textbox with 'Step n' in it :

var x = 1;
$("#323").val("Step 1");
$("#add").click(function (e) {
$("#items").append('<div><input type="text" name="input[]" id="323" value="Step" + x + ":" >');

However, it seems like the x is not taken into account in the listener.

Could someone please help me ?

Thanks !!


Try this (notice the ' before and after x):

$("#items").append('<div><input type="text" name="input[]" id="323" value="Step' + x + ':" >');