Link to home
Start Free TrialLog in
Avatar of isnoend2001
isnoend2001Flag for United States of America

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?
$('#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
                            }
                    }
            });

Open in new window

Avatar of Gary
Gary
Flag of Ireland image

This line is wrong

 t2 = ""||/^(\d+)?([.]?\d{0,2})?$/.test(text)===false?t2 = "Input Numbers Only":t2="";

should be

 t2 == ""||/^(\d+)?([.]?\d{0,2})?$/.test(text)===false?t2 = "Input Numbers Only":t2="";
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
Avatar of isnoend2001

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
What other bits don't you understand
var value = parseFloat($('#in').val());
just about every line
i was hoping to have a comment on each line like this:
  // CHECK FOR A CHANGE IN THE DROP DOWN MENU
     $('#selectPitch').change(function () {
        $('#selectPitchLabel').addClass('Require'); // 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(roofAreaTxt);   // 7-12-2014 Q_28474675
         if (roofAreaVal != 0) {  // CHECK TO MAKE SURE THERE IS A VALUE IN THE DROP DOWNxnew 07-12-14
              $('#selectPitchLabel').removeClass('Require');//xnew 07-12-14
             
             calc(roofAreaVal);  // RUN THE FUNCTION TO MAKE THE CALCULATIONS
             $('#roofMesg').val('Roof ' + newAreaTxt + ' added ' + roofAreaVal);
         }

     });
ASKER CERTIFIED SOLUTION
Avatar of Gary
Gary
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yes Thank you