For currentUnknownBox
, if I use "var" the expected functionality does not work as expected (currentUnknownBox becomes the first element clicked). If I remove the var, it works as expected. I am assuming this has something to do with global scope. Could someone explain this to me?
jQuery(".box.unknown").live('click',function()
{
var currentUnknownBox = this;
//if we are NOT on mobile, use jQuery UI dialog
if (!Drupal.settings.is_mobile)
{
jQuery("#letter-input-dialog").dialog();
jQuery('#letter_input_form').submit(function()
{
var letter = jQuery("#letter_input").val();
jQuery("#letter-input-dialog").dialog('close');
jQuery("#letter_input").val('');
that.validateAndSaveLetter(currentUnknownBox, letter);
//Do not let the form actually submit
return false;
});
}
else
{
var letter = prompt('Please enter a letter to use in your guess');
that.validateAndSaveLetter(that.currentUnknownBox, letter);
}
});
EDIT: The problem is I am re-declaring my submit function every time.