Reputation: 161
so I was making a 'Help' page with some javascript when an error came and I don't know why this is happening because I've already done it the same way and worked right.
my error occurs when I enter help
on the input and press the submit button, it shows me an alert telling me [Object object]. I'm trying to print the very first "help"
string on help variable
.
here is the fiddle : http://jsfiddle.net/3u272/
here is the code
// Toda la ayuda esta guardada en esta cadena de variables
var help = {
"help" : {
title : "help",
description : "Utiliza help mas una de las funciones de a continuación.",
},
};
// Funcion para mostrar la ayuda
var ayudaSubmit = document.form.buscar;
$(ayudaSubmit).on("click", function () {
var helpInputVal = document.form.ayuda.value,
helpQuestion = help[helpInputVal];
if (!helpQuestion) {
alert(helpInputVal + " MEEEEEH!");
} else {
alert(helpQuestion);
};
});
and here the HTML
<form name="form">
<input name="ayuda" type="text" placeholder="help with + la función" id="helpInput"/>
<input name="buscar" type="submit" placeholder="Buscar" value="Buscar" id="ayudaSubmit"/>
</form>
Upvotes: 0
Views: 54
Reputation: 69276
You are alerting the entire object. You may want to alert only the message instead:
Change your second alert()
in:
alert(helpQuestion.description);
Result:
Upvotes: 1
Reputation: 3742
It is because you are printing out the whole object. If you only want to print out the text you should do:
alert(helpQuestion.description);
And a fiddle: http://jsfiddle.net/rLFvM/
Upvotes: 1