Reputation: 464
Writing a resume creator in, in a previous question I was using a for loop to dynamically generate an array from form inputs. Based on another users advice I instead used the .map() method to store the values.
var jobtitle = $('input[id^=jobtitle]').map(function () {
return this.value;
}).get();
Unfortunately I can't figure out how to access the stored values outside of this function!
$('#resumejobs').append('<div id ="resumejob' + jobs + ' "><div id = "jt' + i + ' " ' + 'class = "jobtitle">' + jobtitle[0] +'<br /></div><div class = "joblocation"</div></div>');
I thought that .map() stored the values in a new array named jobtitle, it seems I was wrong because when I run my program, the title of the first job is not displayed in the jobtitle div.
JSFiddle: http://jsfiddle.net/r2EX6/9/
Is there a way to access the data stored in the .map() outside of the function that created it? Or is there some kind of workaround?
Upvotes: 0
Views: 60
Reputation: 104775
You are currently declaring all of your .map()
variables inside this function:
$('#experiencesave').click(function () {
Declare the variables outside this function, then access them and assign them inside here as you normally would. Ex:
var jobtitles;
$('#experiencesave').click(function () {
jobtitles = .....
});
Upvotes: 1