as the title says I am attempting to have my setAnswer() function return true when a button with the class .btnAnswer is clicked, otherwise return false. Then I am passing the value returned to the showHideAnswer() function and using that value for logic. It seems fairly easy and I am not sure where I am going wrong.. I code alot in .NET and am still pretty new to working with Javascript functions. I am sure that it is something easy!
//On partial page load
function pageLoad(sender, args) {
if (args.get_isPartialLoad()) {
showHideAnswers(setAnswer());
alert(setAnswer());
}
}
//Set answer
function setAnswer() {
$("input.btnAnswer[type=submit]").click(function (event) {
//do stuff and return true if clicked
return true;
});
}
//Show hide stuff
function showHideAnswers(flag) {
if(flag){
//do stuff
}
}
Thanks in advance!
P.S. My alert in the page load always shows undefined.
setAnswer, you only assign the click event handler. The handler itself is only executed after the users clicked the element, which is at an arbitrary time aftersetAnswerwas called. If you have to react to the click event somehow, then you have to put all the logic inside the click event handler.