Javascript - I'm not sure how to fill in the data fields in the form. I have to enter a name in the " id=nombre
" field of my form and press the " Ver
" button to see all the data of the object of that name.
I store the data in an array. An object has the following attributes:
Code of the two functions that I should use:
//Devuelve el objeto Disco que está en la posicion i-esima.
this.getDisco = function (pos){
return this.arrayDiscos[pos];
}
//Devuelve verdadero si existe el disco cuyo nombre coincide con el que se pasa.
this.existeDisco = function (nombreRecibido){
var existe = false;
for(var i=0; i<this.arrayDiscos.length; i++){
var nombre = this.arrayDiscos[i].nombre;
if(nombre == nombreRecibido)
existe = true;
}
return existe;
}
Javascript code - event button View:
document.getElementById('ver').addEventListener('click', verDisco, false);
Javascript code - verDisco ():
function verDisco(){
var nombre = document.getElementById('nombre').value;
//Comprobamos si existe el disco en nuestra tienda...
if(miTienda.existeDisco(nombre)){
//Cargamos los datos del objeto cuyo nombre = nombre en los diferentes campos del formulario.
//...
return true;
}else{
//Si NO EXISTE ningún disco con ese titulo/nombre, mensaje.
document.getElementById("errores").innerHTML="NO EXISTE NINGUN DISCO CON EL NOMBRE '"+nombre+"'.";
document.getElementById("nombre").focus();
return false;
}
}
How can I access each attribute of the object in question?