0

Sorry for my code, i am new to javascript and didn't figure out what's going on. My scenario is if there is Group Discount available then I want to use grpDis as a OurCost otherwise I want to use OrgCost as a OurCost.

OrgCost is available on every pages but grpDis only available where group discount is available.

Thank you for the help.

    var OrgCost = '<?=$ourCost;?>';
    var grpDis = document.getElementById('cost1').innerHTML;
    var OurCost;

    if (typeof grpDis!=='undifined') {          
         OurCost = parseInt(changeNumber(grpDis));      
    } else {            
        OurCost = parseInt(changeNumber(OrgCost));
    }

    conslole.log(OurCost);
Dmitry Smorzhok
  • 615
  • 9
  • 20

1 Answers1

-1

Unless you don't need a native javascript implementation I suggest to rely on JQuery. The JQuery way loos like

$(document).ready(function(){
  var grpDis = $('#cost1').innerHTML;
  if (typeof grpDis!=='undefined') {          
     OurCost = parseInt(changeNumber(grpDis));      
  } else {            
    OurCost = parseInt(changeNumber(OrgCost));
  }
});

check out the JQuery web site to download it or load it through a CDN https://jquery.com/download/

Andrea Sindico
  • 7,058
  • 6
  • 41
  • 79