I have new inputs for a multidimensional array. The original inputs that are already defined are displayed correctly when called upon but the new inputs write as "undefined". I think it is recognizing the new inputs as variables. How do you get them to show up as a string?
var original = new Array(); //this is the array
function input(title, artist, ddate, genre, picsrc) {
this.Title = title;
this.Artist = artist;
this.Ddate = parseInt(parseFloat(ddate));
this.Genre = genre;
this.Picsrc = picsrc;
}
original[0] = {title:"Hope II", artist:"Gustav Klimt", ddate:1907, genre:"Art Nouveau", picsrc:"gustav.jpg"}; //and so on
Values that are added to the array are taken from a form.
function addit(form) {
G = form.Title.value //as a test
original[original.length++] = new input(form.Title.value, form.Artist.value, form.Ddate.value, form.Genre.value, form.Picsrc.value)
alert("your entry has been added")
alert(G) //value shows up in the alert
}
but when it is called back in this function:
$("#info").html(original[currentrecord]["title"]+"<br /><h2>"+original[currentrecord]["artist"]+"</h2>"+original[currentrecord]["ddate"]+"<br />"+original[currentrecord]["genre"]);
everything is being written as "undefined". I am assuming that the data is successfully being added to the array, but maybe not in the right format?
I prefer using dot notation, but it's not a requirement.
The real issue is: JavaScript is case sensetive.
I would do it like this:
original[currentrecord].Title
original[currentrecord].Artist
and so on...
At one place in your code you are using all lowercase (when initializing original[0]), but in the constructor function you are using uppercase for the first letter.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.