[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 142
  • Last Modified:

slight adjustment to code written by another EE coder

This page:
http://roofgenius.com/test3.asp

<div id="measureLabel">* Required</div>Text turns black when the value is between 100 and 100,000
if value gets less than 100 or more than 100,000 then label will return to red

<div id="selectPitchLabel">* Required</div> Text turns black when a selection is made
Both labels to be red when the reset button is clicked

<h3 id="Result">Select Pitch</h3>
The <h3 label contains the combobox text when a selection is made. (this part is done)
this needs to be done: Clicking the reset button change the <h3 text to Select Pitch
0
isnoend2001
Asked:
isnoend2001
  • 6
  • 4
1 Solution
 
Scott Fell, EE MVEDeveloperCommented:
The range detection

  if (parseInt(InPutFeet,10) < 100 || parseInt(InPutFeet,10) > 100000){ // TEST IF InPutFeet IS WITHIN RANGE.Q_28474782
               $('#measureLabel').addClass('Require');
         }

Open in new window

Added here
    // THIS FUNCTION WILL RUN ALL OF OUR CALCULATIONS
     function calc(roofAreaVal) {
          // DO ALL OF OUR MATH
         InPutFeet = parseInt($('#in').val(), 10); //InPutFeet = Users input into textbox
         Multipler = parseFloat(roofAreaVal).toFixed(2); //Multipler = ComboBox selected value
         FeetToAdd = (parseInt(InPutFeet, 10) * parseFloat(Multipler)).toFixed(2); //FeetToAdd = InPutFeet * Multipler
         TotalFeet = parseInt(InPutFeet, 10) + parseFloat(FeetToAdd); //TotalFeet = InPutFeet + FeetToAdd		
         TotalSquares = TotalFeet / 100; //TotalSquares = TotalFeet / 100
       TotalSquares = parseFloat(TotalSquares).toFixed(2);
          // UPDATE OUR FIELDS
         $('#Multiplier').text(Multipler);
         $('#FeetAdded').text(FeetToAdd);
         $('#Total').text(TotalFeet);
         $('#TotalSqs').text(TotalSquares);
         if (parseInt(InPutFeet,10) < 100 || parseInt(InPutFeet,10) > 100000){ // TEST IF InPutFeet IS WITHIN RANGE.Q_28474782
               $('#measureLabel').addClass('Require');
         }
     }

 });

Open in new window

0
 
Scott Fell, EE MVEDeveloperCommented:
><div id="selectPitchLabel">* Required</div> Text turns black when a selection is made
Both labels to be red when the reset button is clicked

// THIS FUNCTION WILL CLEAR OUT ALL OF THE FIELDS.  WE RUN THIS WHEN THERE IS AN ERROR
     function clearFields() {  
         $('#in').val('');
         $('#Multiplier').text('Na');
         $('#FeetAdded').text('Na');
         $('#Total').text('Na');
         $('#TotalSqs').text('Na');         
         $('#selectPitch').val(0); //new 07-12-14
         $('#measureLabel').addClass('Require'); // Q_28474782
         $('#selectPitchLabel').addClass('Require');//Q_28474782 
     }

Open in new window

0
 
Scott Fell, EE MVEDeveloperCommented:
<h3 id="Result">Select Pitch</h3>
The <h3 label contains the combobox text when a selection is made. (this part is done)
this needs to be done: Clicking the reset button change the <h3 text to Select Pitch

 
 // THIS FUNCTION WILL CLEAR OUT ALL OF THE FIELDS.  WE RUN THIS WHEN THERE IS AN ERROR
     function clearFields() {  
         $('#in').val('');
         $('#Multiplier').text('Na');
         $('#FeetAdded').text('Na');
         $('#Total').text('Na');
         $('#TotalSqs').text('Na');         
         $('#selectPitch').val(0); //new 07-12-14
         $('#measureLabel').addClass('Require'); // Q_28474782
         $('#selectPitchLabel').addClass('Require');//Q_28474782 
         $('#Result').text('Select Pitch');//Q_28474782 
     }

Open in new window

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Scott Fell, EE MVEDeveloperCommented:
Sample with updates

http://jsbin.com/rupal/1/
0
 
isnoend2001Author Commented:
Thanks Padas i tried your http://jsbin.com/rupal/1
and it calculates even if no combobox selection made
I think the range should include testing the index of the combo
 if (parseInt(InPutFeet,10) < 100 || parseInt(InPutFeet,10) > 100000){ // TEST IF InPutFeet IS WITHIN RANGE.Q_28474782
               $('#measureLabel').addClass('Require');
         }
if number  >= 100 and number  <100000 and Combobox.text <> "Select Pitch" then
do calculation
<> in vb = not
0
 
Scott Fell, EE MVEDeveloperCommented:
This will not calculate if the field is blank

http://jsbin.com/rupal/2
     // UPDATE OUR FIELDS
       if (InPutFeet){
         $('#Multiplier').text(Multipler);
         $('#FeetAdded').text(FeetToAdd);
         $('#Total').text(TotalFeet);
         $('#TotalSqs').text(TotalSquares);
         if (parseInt(InPutFeet,10) < 100 || parseInt(InPutFeet,10) > 100000){ // TEST IF InPutFeet IS WITHIN RANGE.Q_28474782
               $('#measureLabel').addClass('Require');
         }
       }
     }

Open in new window


Option 2 http://jsbin.com/rupal/3
    // UPDATE OUR FIELDS
       if (parseInt(InPutFeet,10) > 100 && parseInt(InPutFeet,10) < 100000){
         $('#Multiplier').text(Multipler);
         $('#FeetAdded').text(FeetToAdd);
         $('#Total').text(TotalFeet);
         $('#TotalSqs').text(TotalSquares);
         
       }else{
         $('#measureLabel').addClass('Require');
         
       }
     }

Open in new window


You probably want something in there that shows the value needs to be between 100 and 100,000
0
 
isnoend2001Author Commented:
I like that jsbin it was different i could copy the the whole page and was not trying to determine if your code goes inside a function or is stand alone
i have given more thought to the not asking for coders by name
I think EE need to have a bonus point to overcome the 500 max
In the past i have had coders get mad if they did not get an A
to overcome that and not have to explain why i always give an A
most of your answers would get a bonus some others would not
This would not From Yesterday I asked for more info this morning
http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Jquery/Q_28474283.html
anyway i have not asked for the range-calculations yet
I will in another question once i get all the bugs worked out
0
 
Scott Fell, EE MVEDeveloperCommented:
Well grading is open to interpretation.     If you did not get a good answer and you grade somebody a "C", you should really have tried to reach out and clarify what you wanted.  If the Expert does not come back to help, then a C is warranted.  

There are times when the Asker views their question as easy and it is not. They end up getting an answer they don't like yet multiple experts concur, "that can't be done"

I know it was not me that added
inVal=inVal==Int(inVal)?Int(inVal):inVal;

and that may have been him.  Although I think simply changing this line
  inVal = inVal.toFixed(1); // USE ONLY ONE DECIMAL PLACE FOR THE  VALUE
to
  inVal = inVal.toFixed(0); // USE ONLY ONE DECIMAL PLACE FOR THE  VALUE

would do the trick

http://jsbin.com/kacen/1/edit
var x = 1232.63432;
var y = x.toFixed(1); // USE ONLY ONE DECIMAL PLACE FOR THE  VALUE
var z = x.toFixed(0); // USE ONLY ONE DECIMAL PLACE FOR THE  VALUE

alert('y='+y +' z='+z);

Open in new window


Part of the issue is there are multiple ways to do the same thing and multiple people are not building on another's code and simply making their own probably because it is easier.  

Typically we do not write all this code and simply  help you with what you have.  As you know, you are copy and pasting what we are doing without really understanding what is anything is doing.  And ultimately you are responsible.

That is why I tried to comment as  much as I could to help make it clear.  There are also short cuts I could have taken and JS can be hard to read if you don't have comments and write the least amount of code possible.

Anyway, this code, inVal=inVal==Int(inVal)?Int(inVal):inVal; was throwing errors.
0
 
isnoend2001Author Commented:
Thanks padas
I have to run a few errands will be back
0
 
isnoend2001Author Commented:
Thank you
looks like everything is in order
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now