javascript increment index in funciton
Posted
by mcgrailm
on Stack Overflow
See other posts from Stack Overflow
or by mcgrailm
Published on 2010-05-03T18:56:27Z
Indexed on
2010/05/03
19:08 UTC
Read the original article
Hit count: 327
I'm just trying to figure out how to create an index inside a function so I can keep track of the items its generating and I'm not sure how to do this seems like I should know this..
addLocation(options,location)
funciton addLocation(options,location){
$('#list').append('<li class="location"><div>'+location.label+'</div>'+
'<input type="hidden" name="location['+x+'][lat]" value="'+location.lat+'" />'+
'<input type="hidden" name="location['+x+'][lon]" value="'+location.lon+'" />'+
'<input type="hidden" name="location['+x+'][loc]" value="'+location.loc+'" />'+
'<input type="hidden" name="location['+x+'][label]" value="'+location.label+'" />'+
'</li>');
}
now normally you have a forloop to help you keep track of things but int this instance I'm not appending items in a loop and I keep getting an error saying x in undefined
appreciate any help you can give
thanks Mike
© Stack Overflow or respective owner