2

I'm new at this. The input is showing in the text box but not making the calculation for the if statement.

enter image description here

$w.onReady(function () {
$w("#generatequote").onClick((event) => {

var SR = Number($w("#SR").value);
    if (SR<100) {
        $w("#quotetext").value = SR * 2;
    }

    //first try- does not calculate
    $w("#quotetext").value = fin  + "\n" + (name + "\n" + email + "\n" + phonenumber + "\n" + address + "\n" 
    + ($w("#quotetext").value = SR))

    //Second Try- does not calculate
    $w("#quotetext").value = fin  + "\n" + (name + "\n" + email + "\n" + phonenumber + "\n" + address + "\n" 
    + ($w("#SR").value = SR))

I have also tried replacing "#quotetext" in the if statement with "#SR" but it displays nothing

This is the code displaying the additional else statements

var SR = Number($w("#SR").value);
if (SR<100) {
$w("#quotetext").value = SR * 2;
}
else if (SR>=100&&SR<300) {
$w("#quotetext").value = SR * 1.5;
    }
    else if (SR>=300&&SR<600) {
        $w("#quotetext").value * 1.25;
    }
    else if(SR>=600) {
        $w("#SR").value = ("SR");
    }
    $w("#quotetext").value = fin  + "\n" + (name + "\n" + email + "\n" + phonenumber + "\n" + address + "\n" + ($w("#SR").value = SR))

1 Answers1

1

You are reassigning your $w("#quotetext").value after the if statement ends. Either put the next code in else blocks or the previous outputs won't be shown as they will get replaced by later ones. Just don't reassign the $w("#quotetext").value after your if statements end, or use a variable in your if statements instead of using $w("#quotetext").value

var SR = Number($w("#SR").value);
if (SR<100) {
    SR = SR * 2;
}
else if (SR>=100&&SR<300) {
    SR = SR * 1.5;
    }
    else if (SR>=300&&SR<600) {
        SR= SR * 1.25;
    }
    else if(SR>=600) {
        SR = ("SR");
    }
    $w("#quotetext").value = fin  + "\n" + (name + "\n" + email + "\n" + phonenumber + "\n" + address + "\n" + (SR))
Hamza Khurshid
  • 765
  • 7
  • 18
  • hi, thanks for the help. I had removed some of my else statments from the example to be more specific about my problem. . I understand what you're saying about reassigning $w("#quotetext") and I think you're right but I'm not sure how to replace it and still have the result of the if statement display in the "quotetext" text box. – Vincent Morley Mar 16 '19 at 19:55
  • I've added some more of my code to show the else statements. The goal is to get the final line of code to write the text input elements as well as the SR variable calculated for the if statement – Vincent Morley Mar 16 '19 at 20:01
  • I have fixed your variable use. It should work for you now! – Hamza Khurshid Mar 17 '19 at 04:40