I have some variables that I want to use in jQuery's focus event. How do I declare them so they are in the focus callback?
var height = 72;
$('#myfield').focus(function() {
heightinfeet = height / 12;
alert(heightinfeet);
});
For me, height is always 0. There are several variables to pass and I've tried making it an object using this for properties and that didn't pass them in either
/* real code */
function GOPRO_pfFieldConfirmation(oField1, oField2, oMarkerField, bCaseSens) {
var GOPRO_iFieldLen1 = $(oField1).val().length;
var GOPRO_iFieldLen2 = $(oField2).val().length;
var GOPRO_sFieldVal1 = $(oField1).val();
var GOPRO_sFieldVal2 = $(oField2).val();
var GOPRO_sFieldSub = GOPRO_sFieldVal1.substring(0, GOPRO_iFieldLen2);
//if not case sensitive, make all upper case
if (bCaseSens == false) {
GOPRO_sFieldVal1 = GOPRO_sFieldVal1.toUpperCase();
GOPRO_sFieldVal2 = GOPRO_sFieldVal2.toUpperCase();
GOPRO_sFieldSub = GOPRO_sFieldSub.toUpperCase();
}
$(oField1).focus( function() {
console.log(GOPRO_iFieldLen1);
if ((GOPRO_sFieldVal1 == GOPRO_sFieldVal2) && GOPRO_iFieldLen1 > 0) {
GreenMarker();
}
else if (GOPRO_iFieldLen1 > 0 && GOPRO_iFieldLen2 > 0) {
RedMarker();
}
else {
NoMarker();
}
});
...
GOPRO_pfFieldConfirmation($('#reg_email'), $('#reg_email2'), $('.field_confirm:eq(3)'), false);
console.log is always 0, actually all the predefined variables return 0 or null strings