Search
Mar 17, 2019

IF LESS THAN (INPUT33) SHOW/HIDE ELEMENT

2 comments20 views

Hello,

Having a weird issue.

I would like to show or hide a element based on the comparison of two input field values.

so far, my code is written to check for the "NewAge" from Input93 and if the NewAge is LESS than input35 (OldAge) "Decrease" shoes and "Increase hides.

and if the New Age is MORE than the Old Age then Decrease hides and Increase shows.

The problem... it works sometimes and other times the wrong information displays.

When I run my "Calculator" I run into issues .

This is the result I get...

which is showing the "Increase" element when the NEW age is LESS than the OLD age...and it should be the opposite.

here is my editor link:

https://editor.wix.com/html/editor/web/renderer/edit/f504e3e4-d98b-424b-9cd6-ee85acbf0a13?metaSiteId=78132c96-6114-45f5-8295-944cd55e4ecc&editorSessionId=ad758888-76ac-49e8-a659-876938a202bf&referralInfo=my-account

Here is the code used:

export function SeeDifference_click(event) { $w("#slider").next(); $w("#ChartBox").expand(); $w("#Back3").show(); // Tradeline Recommendations // 1 year $w('#input51').value = "1"; // Minimum Tradeline Credit Age for 1 pre existing card // $w('#input65').value = (Number($w('#input51').value) + (Number($w('#input31').value))); //combines card fico age with recommended fico age for FICO NEW TOTAL $w('#input79').value = (Number($w('#input65').value) /2); $w('#input93').value = (Number($w('#input79').value).toFixed(2).toString()); // NEW FICO Age Rounded // card 1 of 1 $w('#ExampleYr1').text = $w('#input93').value + " YRS"; var NewAge = $w("#input93").value;

if (NewAge <= $w("#input35").value) { $w("#1yrDecrease").show(); $w("#1yrIncrease").hide(); }else if (NewAge >= $w("#input35").value) { $w("#1yrDecrease").hide(); $w("#1yrIncrease").show(); } // Tradeline Recommendations // 2 year $w('#input52').value = "2"; // Minimum Tradeline Credit Age for 1 pre existing card // $w('#input66').value = (Number($w('#input52').value) + (Number($w('#input31').value))); //combines card fico age with recommended fico age for FICO NEW TOTAL $w('#input80').value = (Number($w('#input66').value) /2); $w('#input94').value = (Number($w('#input80').value).toFixed(2).toString()); // NEW FICO Age Rounded // card 1 of 1 $w('#ExampleYr2').text = $w('#input94').value + " YRS"; var NewAge2 = $w("#input94").value;

if (NewAge2 <= $w("#input35").value) { $w("#2yrDecrease").show(); $w("#2yrIncrease").hide(); }else if (NewAge2 >= $w("#input35").value) { $w("#2yrDecrease").hide(); $w("#2yrIncrease").show(); } // Tradeline Recommendations // 3 year $w('#input53').value = "3"; // Minimum Tradeline Credit Age for 1 pre existing card // $w('#input67').value = (Number($w('#input53').value) + (Number($w('#input31').value))); //combines card fico age with recommended fico age for FICO NEW TOTAL $w('#input81').value = (Number($w('#input67').value) /2); $w('#input95').value = (Number($w('#input81').value).toFixed(2).toString()); // NEW FICO Age Rounded // card 1 of 1 $w('#ExampleYr3').text = $w('#input95').value + " YRS"; var NewAge3 = $w("#input95").value;

if (NewAge3 <= $w("#input35").value) { $w("#3yrDecrease").show(); $w("#3yrIncrease").hide(); }else if (NewAge3 >= $w("#input35").value) { $w("#3yrDecrease").hide(); $w("#3yrIncrease").show(); } // Tradeline Recommendations // 4 year $w('#input54').value = "4"; // Minimum Tradeline Credit Age for 1 pre existing card // $w('#input68').value = (Number($w('#input54').value) + (Number($w('#input31').value))); //combines card fico age with recommended fico age for FICO NEW TOTAL $w('#input82').value = (Number($w('#input68').value) /2); $w('#input96').value = (Number($w('#input82').value).toFixed(2).toString()); // NEW FICO Age Rounded // card 1 of 1 $w('#ExampleYr4').text = $w('#input96').value + " YRS"; var NewAge4 = $w("#input96").value;

if (NewAge4 <= $w("#input35").value) { $w("#4yrDecrease").show(); $w("#4yrIncrease").hide(); }else if (NewAge4 >= $w("#input35").value) { $w("#4yrDecrease").hide(); $w("#4yrIncrease").show(); } // Tradeline Recommendations // 5 year $w('#input55').value = "5"; // Minimum Tradeline Credit Age for 1 pre existing card // $w('#input69').value = (Number($w('#input55').value) + (Number($w('#input31').value))); //combines card fico age with recommended fico age for FICO NEW TOTAL $w('#input83').value = (Number($w('#input69').value) /2); $w('#input97').value = (Number($w('#input83').value).toFixed(2).toString()); // NEW FICO Age Rounded // card 1 of 1 $w('#ExampleYr5').text = $w('#input97').value + " YRS"; var NewAge5 = $w("#input97").value;

if (NewAge5 <= $w("#input35").value) { $w("#5yrDecrease").show(); $w("#5yrIncrease").hide(); }else if (NewAge5 >= $w("#input35").value) { $w("#5yrDecrease").hide(); $w("#5yrIncrease").show(); } // Tradeline Recommendations // 6 year $w('#input56').value = "6"; // Minimum Tradeline Credit Age for 1 pre existing card // $w('#input70').value = (Number($w('#input56').value) + (Number($w('#input31').value))); //combines card fico age with recommended fico age for FICO NEW TOTAL $w('#input84').value = (Number($w('#input70').value) /2); $w('#input98').value = (Number($w('#input84').value).toFixed(2).toString()); // NEW FICO Age Rounded // card 1 of 1 $w('#ExampleYr6').text = $w('#input98').value + " YRS"; var NewAge6 = $w("#input98").value;

if (NewAge6 <= $w("#input35").value) { $w("#6yrDecrease").show(); $w("#6yrIncrease").hide(); }else if (NewAge6 >= $w("#input35").value) { $w("#6yrDecrease").hide(); $w("#6yrIncrease").show(); } // Tradeline Recommendations // 7 year $w('#input57').value = "7"; // Minimum Tradeline Credit Age for 1 pre existing card // $w('#input71').value = (Number($w('#input57').value) + (Number($w('#input31').value))); //combines card fico age with recommended fico age for FICO NEW TOTAL $w('#input85').value = (Number($w('#input71').value) /2); $w('#input99').value = (Number($w('#input85').value).toFixed(2).toString()); // NEW FICO Age Rounded // card 1 of 1 $w('#ExampleYr7').text = $w('#input99').value + " YRS"; var NewAge7 = $w("#input99").value;

if (NewAge7 <= $w("#input35").value) { $w("#7yrDecrease").show(); $w("#7yrIncrease").hide(); }else if (NewAge7 >= $w("#input35").value) { $w("#7yrDecrease").hide(); $w("#7yrIncrease").show(); } // Tradeline Recommendations // 8 year $w('#input58').value = "8"; // Minimum Tradeline Credit Age for 1 pre existing card // $w('#input72').value = (Number($w('#input58').value) + (Number($w('#input31').value))); //combines card fico age with recommended fico age for FICO NEW TOTAL $w('#input86').value = (Number($w('#input72').value) /2); $w('#input100').value = (Number($w('#input86').value).toFixed(2).toString()); // NEW FICO Age Rounded // card 1 of 1 $w('#ExampleYr8').text = $w('#input100').value + " YRS"; var NewAge8 = $w("#input100").value;

if (NewAge8 <= $w("#input35").value) { $w("#8yrDecrease").show(); $w("#8yrIncrease").hide(); }else if (NewAge8 > $w("#input35").value) { $w("#8yrDecrease").hide(); $w("#8yrIncrease").show(); } // Tradeline Recommendations // 9 year $w('#input59').value = "9"; // Minimum Tradeline Credit Age for 1 pre existing card // $w('#input73').value = (Number($w('#input59').value) + (Number($w('#input31').value))); //combines card fico age with recommended fico age for FICO NEW TOTAL $w('#input87').value = (Number($w('#input73').value) /2); $w('#input101').value = (Number($w('#input87').value).toFixed(2).toString()); // NEW FICO Age Rounded // card 1 of 1 $w('#ExampleYr9').text = $w('#input101').value + " YRS"; var NewAge9 = $w("#input101").value;

if (NewAge9 <= $w("#input35").value) { $w("#9yrDecrease").show(); $w("#9yrIncrease").hide(); }else if (NewAge9 > $w("#input35").value) { $w("#9yrDecrease").hide(); $w("#9yrIncrease").show(); } // Tradeline Recommendations // 10 year $w('#input60').value = "10"; // Minimum Tradeline Credit Age for 1 pre existing card // $w('#input74').value = (Number($w('#input60').value) + (Number($w('#input31').value))); //combines card fico age with recommended fico age for FICO NEW TOTAL $w('#input88').value = (Number($w('#input74').value) /2); $w('#input102').value = (Number($w('#input88').value).toFixed(2).toString()); // NEW FICO Age Rounded // card 1 of 1 $w('#ExampleYr10').text = $w('#input102').value + " YRS"; var NewAge10 = $w("#input102").value;

if (NewAge10 <= $w("#input35").value) { $w("#10yrDecrease").show(); $w("#10yrIncrease").hide(); }else if (NewAge10 > $w("#input35").value) { $w("#10yrDecrease").hide(); $w("#10yrIncrease").show(); } // Tradeline Recommendations // 11 year $w('#input61').value = "11"; // Minimum Tradeline Credit Age for 1 pre existing card // $w('#input75').value = (Number($w('#input61').value) + (Number($w('#input31').value))); //combines card fico age with recommended fico age for FICO NEW TOTAL $w('#input89').value = (Number($w('#input75').value) /2); $w('#input103').value = (Number($w('#input89').value).toFixed(2).toString()); // NEW FICO Age Rounded // card 1 of 1 $w('#ExampleYr11').text = $w('#input103').value + " YRS"; var NewAge11 = $w("#input103").value;

if (NewAge11 <= $w("#input35").value) { $w("#11yrDecrease").show(); $w("#11yrIncrease").hide(); }else if (NewAge11 > $w("#input35").value) { $w("#11yrDecrease").hide(); $w("#11yrIncrease").show(); } // Tradeline Recommendations // 12 year $w('#input62').value = "12"; // Minimum Tradeline Credit Age for 1 pre existing card // $w('#input76').value = (Number($w('#input62').value) + (Number($w('#input31').value))); //combines card fico age with recommended fico age for FICO NEW TOTAL $w('#input90').value = (Number($w('#input76').value) /2); $w('#input104').value = (Number($w('#input90').value).toFixed(2).toString()); // NEW FICO Age Rounded // card 1 of 1 $w('#ExampleYr12').text = $w('#input104').value + " YRS"; var NewAge12 = $w("#input104").value;

if (NewAge12 <= $w("#input35").value) { $w("#12yrDecrease").show(); $w("#12yrIncrease").hide(); }else if (NewAge12 > $w("#input35").value) { $w("#12yrDecrease").hide(); $w("#12yrIncrease").show(); } // Tradeline Recommendations // 13 year $w('#input63').value = "13"; // Minimum Tradeline Credit Age for 1 pre existing card // $w('#input77').value = (Number($w('#input63').value) + (Number($w('#input31').value))); //combines card fico age with recommended fico age for FICO NEW TOTAL $w('#input91').value = (Number($w('#input77').value) /2); $w('#input105').value = (Number($w('#input91').value).toFixed(2).toString()); // NEW FICO Age Rounded // card 1 of 1 $w('#ExampleYr13').text = $w('#input105').value + " YRS"; var NewAge13 = $w("#input105").value;

if (NewAge13 <= $w("#input35").value) { $w("#13yrDecrease").show(); $w("#13yrIncrease").hide(); }else if (NewAge13 > $w("#input35").value) { $w("#13yrDecrease").hide(); $w("#13yrIncrease").show(); } // Tradeline Recommendations // 14 year $w('#input64').value = "14"; // Minimum Tradeline Credit Age for 1 pre existing card // $w('#input78').value = (Number($w('#input64').value) + (Number($w('#input31').value))); //combines card fico age with recommended fico age for FICO NEW TOTAL $w('#input92').value = (Number($w('#input78').value) /2); $w('#input106').value = (Number($w('#input92').value).toFixed(2).toString()); // NEW FICO Age Rounded // card 1 of 1 $w('#ExampleYr14').text = $w('#input106').value + " YRS"; var NewAge14 = $w("#input106").value;

if (NewAge14 <= $w("#input35").value) { $w("#14yrDecrease").show(); $w("#14yrIncrease").hide(); }else if (NewAge14 > $w("#input35").value) { $w("#14yrDecrease").hide(); $w("#14yrIncrease").show(); }

Mar 18, 2019Edited: Mar 18, 2019

Hi, Shaneice Williams.

I agree with Yisrael that it's a lot of code that you have there.

For now, since I have to knock off other work, I would at the very least recommend that you name all your controls with meaningful (mnemonic) names. For example, if you rename "input93" to "newAge", then you won't have to assign it like follows:

 var NewAge = $w("#input93"#input93").value; 

but can simply refer to

$w("#newAge"#newAge").value;

That makes the name meaningful (and, as a result, immediately usable [reference-able]).

Here's another example along the same line (to reinforce the concept): I recommend renaming "input63" to "minimumTradelineCreditAgeFor1PreEistingCard"

$w('#input63').value = "13"; // Minimum Tradeline Credit Age for 1 pre existing card //

I also recommend that you indent code 2 spaces within structures like if, etc. so that it's immediately evident that the code is within (not outside) the structure.

HTH,

Art Bergquist

P.S. Not sure why but it appears that some of the text in my post gets doubled up (duplicated); I didn't do that and while I'm typing this, it's not doubled up ... only after I [Publish] it.

Log In to Comment
Get in on the conversation.
Sign Up Today
Not a member yet? Join our community to post and comment.