isnoend2001
asked on
Comment jquery code
i finally got his page done with all the help from you experts
could someone comment this code, its over my head?
could someone comment this code, its over my head?
$('#in').on('input propertychange', function () {
var text = $(this).val();
var t2 = text.replace(/[^\d\.]/g, "")
.replace(/\./, "z")
.replace(/\./g, "")
.replace(/z/, ".");
t2 = ""||/^(\d+)?([.]?\d{0,2})?$/.test(text)===false?t2 = "Input Numbers Only":t2="";
if(t2==="Input Numbers Only"){alert(t2);}
$('#in').on('keyup', function() {
if ($('#in').val().length > 0) {
var strValue = $('#in').val();
if (strValue.indexOf('.') > -1) {
if (strValue.split('.')[1].length > 1) {
$('#in').val(strValue.substring(0, strValue.length - 1));
}
}
var value = parseFloat($('#in').val());
if (value > 90000) {
value = Math.floor(value);
value /= 10;
value = Math.floor(value);
value = value.toFixed(0);
$('#in').val(value);
$('#measureLabel').removeClass('Require');
}
roofAreaVal = $('#selectPitch option:selected').val();
if (value < 100) {
$('#measureLabel').addClass('Require');
calc(roofAreaVal); // call calc fnction
} else {
$('#measureLabel').removeClass('Require');
calc(roofAreaVal); // call calc fnction
}
}
});
The regex is checking the input is a number with only one period (full stop)
The keyup function checks if there is more than one period in the value, if there is then it removes everything after the second period.
If value is greater than 90000 then round the number down to the nearest integer, divide by 10, round down again, and set the inputs value to this new number
The rest is pretty much self explanatory
The keyup function checks if there is more than one period in the value, if there is then it removes everything after the second period.
If value is greater than 90000 then round the number down to the nearest integer, divide by 10, round down again, and set the inputs value to this new number
The rest is pretty much self explanatory
ASKER
thanks Gary
I made the change and it still works
http://roofgenius.com/test2.asp
as far as The rest is pretty much self explanatory, maybe to you but not to me
I made the change and it still works
http://roofgenius.com/test2.asp
as far as The rest is pretty much self explanatory, maybe to you but not to me
What other bits don't you understand
ASKER
var value = parseFloat($('#in').val()) ;
just about every line
just about every line
ASKER
i was hoping to have a comment on each line like this:
// CHECK FOR A CHANGE IN THE DROP DOWN MENU
$('#selectPitch').change(f unction () {
$('#selectPitchLabel').add Class('Req uire'); // RESET LABEL
var roofAreaVal = $(this).val(); // GET VALUE OF DROPDOWN xnew 07-12-14
var roofAreaTxt = $('#selectPitch option:selected').text(); //GET VALUE OF THE TEXT OF THE DROP DOWN
var rat = roofAreaTxt.split(' '); // CONVERT THE TEXT OF THE DROP DOWN TO AN ARRAY. REQUIRED TO REVERSE USAGE IN HE MESSAGE
var newAreaTxt = rat[1] + ' ' + rat[0]; // REVERSE THE ORDER OF THE TEXT
$('#Result').text(roofArea Txt); // 7-12-2014 Q_28474675
if (roofAreaVal != 0) { // CHECK TO MAKE SURE THERE IS A VALUE IN THE DROP DOWNxnew 07-12-14
$('#selectPitchLabel').rem oveClass(' Require'); //xnew 07-12-14
calc(roofAreaVal); // RUN THE FUNCTION TO MAKE THE CALCULATIONS
$('#roofMesg').val('Roof ' + newAreaTxt + ' added ' + roofAreaVal);
}
});
// CHECK FOR A CHANGE IN THE DROP DOWN MENU
$('#selectPitch').change(f
$('#selectPitchLabel').add
var roofAreaVal = $(this).val(); // GET VALUE OF DROPDOWN xnew 07-12-14
var roofAreaTxt = $('#selectPitch option:selected').text(); //GET VALUE OF THE TEXT OF THE DROP DOWN
var rat = roofAreaTxt.split(' '); // CONVERT THE TEXT OF THE DROP DOWN TO AN ARRAY. REQUIRED TO REVERSE USAGE IN HE MESSAGE
var newAreaTxt = rat[1] + ' ' + rat[0]; // REVERSE THE ORDER OF THE TEXT
$('#Result').text(roofArea
if (roofAreaVal != 0) { // CHECK TO MAKE SURE THERE IS A VALUE IN THE DROP DOWNxnew 07-12-14
$('#selectPitchLabel').rem
calc(roofAreaVal); // RUN THE FUNCTION TO MAKE THE CALCULATIONS
$('#roofMesg').val('Roof ' + newAreaTxt + ' added ' + roofAreaVal);
}
});
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yes Thank you
t2 = ""||/^(\d+)?([.]?\d{0,2})?
should be
t2 == ""||/^(\d+)?([.]?\d{0,2})?