I’m working on an application where the users guesses on a number (7 trues). The app contains of an input field as well as a button, and if the user hasn’t got more guesses the input field as well as the button is disabled, and a new button appears (restart).
In my code behind-file is the code for checking if the user has more guesses or not, and if not the following code takes care of the disabling/enabling of the buttons:
code behind-file:
...
btnCheckNr.Enabled = false;
inputBox.Enabled = false;
newGame.Visible = true;
...
I’m not using ViewState but Session state, and every time a postpack is done the fields is back as they were from the start, ie. enabled. Every time the user has made a guess the input field gets focus and the content inside (eg. last guess made) gets selected. This works accept for when the field and button gets disabled, and by that reason I’ve added a check to see if the input field is disabled or not. If so, focus and selection shall not be done (otherwise I get an error).
However, with this code the input field never gets focus, why is that? Is it something that I’m doing wrong and in that case how could this be accomplished?
Thanks in advance!
external.js:
var Capsule = {
init: function() {
var input = $('#inputBox');
if (!input.is(":disabled"))
input.focus();
input.select();
}
}
}
window.onload = Capsule.init;
Try triggering a click instead:
Demo.