facebook

Best way to use static data in function? Newbie Warning! :)

💡
Our Forums Have Moved

For help with installation, bugs reports or feature requests, please head over to our new forums.
Genuitec Community on GitHub

  1. MobiOne Archive
  2.  > 
  3. Getting Help – General
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #341762 Reply

    dannyg280
    Member

    I am building a cost calculator app. Depending on the product name selected from a combobox, different text fields, text areas and comboboxs are populated with data relating to that product. I currently have the entire code below in the On Change action of the Combobox and I know this is not the best/simplest/cleanest way to do this.

    I beleive all functions should be put in the custom.js file, and then called from the action, but I can’t seem to get that too get it to work. If I place the entire code below inside a “function.productname() { code in here};” and then put productname() in the on change event it doesn’t work.

    The other thing is I feel I should be using an external file…maybe text or XML, and then using variables to put all this static info (and I assume it would allow easier updating). I’m a newbie so if someone could point me in the right direction. Maybe even give me a small bit of sample code it would be greatly appreciated.

    (It’s a lot of code, but once you read the first couple if statements you should get the gist of it)

    
    $genpname = $("select[name='genpname']");
    $curcostrtu = $('#m1-GCC-rtugalcost').text();
    $gencostrtu = $('#m1-GCC-genrtugalcost').text();
    $savings = $('#m1-GCC-savings').text();
    if ($(this).val() == "GPF") {
    $('#m1-GCC-dilrate').text("64");
    $('#m1-GCC-curunitper').text("4");
    $('#m1-GCC-rtugal').text("260");
    $('#m1-GCC-listprice').val("94.00");
    $('#m1-GCC-rtugalcost').text("0.36");
    $("select[name='genpname'] option").remove();
    $("<option />").val("PI-GPC").text("PolGreen Indoors").appendTo($genpname);
    $('#m1-GCC-gendilrate').text("64");
    $('#m1-GCC-genunitper').text("5.28");
    $('#m1-GCC-genrtugal').text("343");
    $('#m1-GCC-genprice').val("294.62");
    $('#m1-GCC-genrtugalcost').text("0.86");
      
      };
      if ($(this).val() == "HS") {
    $('#m1-GCC-dilrate').text("32");
    $('#m1-GCC-curunitper').text("4");
    $('#m1-GCC-rtugal').text("132");
    $('#m1-GCC-listprice').val("80.64");
    $('#m1-GCC-rtugalcost').text("0.61");
     $("select[name='genpname'] option").remove();
    $("<option />").val("DU-HDFC").text("Delta Ultra").appendTo($genpname);
    $('#m1-GCC-gendilrate').text("30");
    $('#m1-GCC-genunitper').text("2.64");
    $('#m1-GCC-genrtugal').text("82");
    $('#m1-GCC-genprice').val("121.30");
    $('#m1-GCC-genrtugalcost').text("1.48");
    
    
      };
      
    if ($(this).val() == "BM") {
    $('#m1-GCC-dilrate').text("12");
    $('#m1-GCC-curunitper').text("3");
    $('#m1-GCC-rtugal').text("39");
    $('#m1-GCC-listprice').val("256.40");
    $('#m1-GCC-rtugalcost').text("6.57");
    $("select[name='genpname'] option").remove();
    $("<option />").val("GF-AD").text("GeneFect").appendTo($genpname);
    $('#m1-GCC-gendilrate').text("64");
    $('#m1-GCC-genunitper').text("4");
    $('#m1-GCC-genrtugal').text("260");
    $('#m1-GCC-genprice').val("85.38");
    $('#m1-GCC-genrtugalcost').text("0.33");
    
      };
      
    if ($(this).val() == "RD") {
    $('#m1-GCC-dilrate').text("64");
    $('#m1-GCC-curunitper').text("4");
    $('#m1-GCC-rtugal').text("260");
    $('#m1-GCC-listprice').val("69.28");
    $('#m1-GCC-rtugalcost').text("0.27");
    $("select[name='genpname'] option").remove();
    $("<option />").val("DM-NFC").text("Delta Mild").appendTo($genpname);
    $('#m1-GCC-gendilrate').text("256");
    $('#m1-GCC-genunitper').text("2.64");
    $('#m1-GCC-genrtugal').text("679");
    $('#m1-GCC-genprice').val("116.35");
    $('#m1-GCC-genrtugalcost').text("0.17");
    
      };
      
    if ($(this).val() == "Profi") {
    $('#m1-GCC-dilrate').text("32");
    $('#m1-GCC-curunitper').text("4");
    $('#m1-GCC-rtugal').text("132");
    $('#m1-GCC-listprice').val("119.80");
    $('#m1-GCC-rtugalcost').text("0.91");
    $("select[name='genpname'] option").remove();
    $("<option />").val("DU-FCD").text("Delta Ultra").appendTo($genpname);
    $('#m1-GCC-gendilrate').text("80");
    $('#m1-GCC-genunitper').text("2.64");
    $('#m1-GCC-genrtugal').text("214");
    $('#m1-GCC-genprice').val("121.30");
    $('#m1-GCC-genrtugalcost').text("0.57");
    
      };
      
    if ($(this).val() == "Perd") {
    $('#m1-GCC-dilrate').text("16");
    $('#m1-GCC-curunitper').text("4");
    $('#m1-GCC-rtugal').text("68");
    $('#m1-GCC-listprice').val("268.00");
    $('#m1-GCC-rtugalcost').text("3.98");
    $("select[name='genpname'] option").remove();
    $("<option />").val("OP-PC").text("OxyPure").appendTo($genpname);
    $('#m1-GCC-gendilrate').text("64");
    $('#m1-GCC-genunitper').text("4");
    $('#m1-GCC-genrtugal').text("260");
    $('#m1-GCC-genprice').val("141.93");
    $('#m1-GCC-genrtugalcost').text("0.55");
    
      };
      
    if ($(this).val() == "Virex") {
    $('#m1-GCC-dilrate').text("256");
    $('#m1-GCC-curunitper').text("4");
    $('#m1-GCC-rtugal').text("1028");
    $('#m1-GCC-listprice').val("121.99");
    $('#m1-GCC-rtugalcost').text("0.12");
     $("select[name='genpname'] option").remove();
    $("<option />").val("HF-FFD").text("HyperFect 256").appendTo($genpname);
    $('#m1-GCC-gendilrate').text("256");
    $('#m1-GCC-genunitper').text("4");
    $('#m1-GCC-genrtugal').text("1028");
    $('#m1-GCC-genprice').val("163.33");
    $('#m1-GCC-genrtugalcost').text("0.16");
    
      };
      
    if ($(this).val() == "BS") {
    $('#m1-GCC-dilrate').text("64");
    $('#m1-GCC-curunitper').text("4");
    $('#m1-GCC-rtugal').text("260");
    $('#m1-GCC-listprice').val("66.13");
    $('#m1-GCC-rtugalcost').text("0.25");
    $("select[name='genpname'] option").remove();
    $("<option />").val("NF-ND").text("NeutraFect").appendTo($genpname);
    $('#m1-GCC-gendilrate').text("64");
    $('#m1-GCC-genunitper').text("4");
    $('#m1-GCC-genrtugal').text("260");
    $('#m1-GCC-genprice').val("76.36");
    $('#m1-GCC-genrtugalcost').text("0.29");
    
      };
      
    if ($(this).val() == "BlueHDFC") {
    $('#m1-GCC-dilrate').text("64");
    $('#m1-GCC-curunitper').text("4");
    $('#m1-GCC-rtugal').text("260");
    $('#m1-GCC-listprice').val("80.85");
    $('#m1-GCC-rtugalcost').text("0.31");
     $("select[name='genpname'] option").remove();
    $("<option />").val("DU-HDFC").text("Delta Ultra").appendTo($genpname);
    $('#m1-GCC-gendilrate').text("30");
    $('#m1-GCC-genunitper').text("2.64");
    $('#m1-GCC-genrtugal').text("82");
    $('#m1-GCC-genprice').val("121.30");
    $('#m1-GCC-genrtugalcost').text("1.48");
    
    
    
    };
    
    if ($(this).val() == "BlueAPC") {
    $('#m1-GCC-dilrate').text("10");
    $('#m1-GCC-curunitper').text("4");
    $('#m1-GCC-rtugal').text("44");
    $('#m1-GCC-listprice').val("80.85");
    $('#m1-GCC-rtugalcost').text("1.84");
    $("select[name='genpname'] option").remove();
    $("<option />").val("PI-GPC").text("PolGreen Indoors").appendTo($genpname);
    $('#m1-GCC-gendilrate').text("64");
    $('#m1-GCC-genunitper').text("5.28");
    $('#m1-GCC-genrtugal').text("343");
    $('#m1-GCC-genprice').val("294.62");
    $('#m1-GCC-genrtugalcost').text("0.86");
    
      };
      
    if ($(this).val() == "SB") {
    $('#m1-GCC-dilrate').text("10");
    $('#m1-GCC-curunitper').text("3");
    $('#m1-GCC-rtugal').text("33");
    $('#m1-GCC-listprice').val("241.21");
    $('#m1-GCC-rtugalcost').text("7.31");
    $("select[name='genpname'] option").remove();
    $("<option />").val("DU-HDS").text("Delta Ultra").appendTo($genpname);
    $('#m1-GCC-dilrate').text("7");
    $('#m1-GCC-curunitper').text("2.64");
    $('#m1-GCC-rtugal').text("21");
    $('#m1-GCC-listprice').val("121.30");
    $('#m1-GCC-rtugalcost').text("5.74");
    
    
      };
    
    if ($(this).val() == "SU") {
    $('#m1-GCC-dilrate').text("64");
    $('#m1-GCC-curunitper').text("4");
    $('#m1-GCC-rtugal').text("260");
    $('#m1-GCC-listprice').val("70.47");
    $('#m1-GCC-rtugalcost').text("0.27");
    $("select[name='genpname'] option").remove();
    $("<option />").val("DM-NFC").text("Delta Mild").appendTo($genpname);
    $('#m1-GCC-gendilrate').text("256");
    $('#m1-GCC-genunitper').text("2.64");
    $('#m1-GCC-genrtugal').text("679");
    $('#m1-GCC-genprice').val("116.35");
    $('#m1-GCC-genrtugalcost').text("0.17");
    
      };
      
    if ($(this).val() == "XLHDSC") {
    $('#m1-GCC-dilrate').text("4");
    $('#m1-GCC-curunitper').text("4");
    $('#m1-GCC-rtugal').text("20");
    $('#m1-GCC-listprice').val("96.85");
    $('#m1-GCC-rtugalcost').text("4.84");
    $("select[name='genpname'] option").remove();
    $("<option />").val("DU-HDS").text("Delta Ultra").appendTo($genpname);
    $('#m1-GCC-gendilrate').text("7");
    $('#m1-GCC-genunitper').text("2.64");
    $('#m1-GCC-genrtugal').text("21");
    $('#m1-GCC-genprice').val("121.30");
    $('#m1-GCC-genrtugalcost').text("5.74");
    
      };
    
    if ($(this).val() == "XLFCD") {
    $('#m1-GCC-dilrate').text("8");
    $('#m1-GCC-curunitper').text("4");
    $('#m1-GCC-rtugal').text("36");
    $('#m1-GCC-listprice').val("96.85");
    $('#m1-GCC-rtugalcost').text("2.69");
    $("select[name='genpname'] option").remove();
    $("<option />").val("DU-FCD").text("Delta Ultra").appendTo($genpname);
    $('#m1-GCC-gendilrate').text("80");
    $('#m1-GCC-genunitper').text("2.64");
    $('#m1-GCC-genrtugal').text("214");
    $('#m1-GCC-genprice').val("121.30");
    $('#m1-GCC-genrtugalcost').text("0.57");
    
      };
      
      
    if ($(this).val() == "LQ") {
    $('#m1-GCC-dilrate').text("64");
    $('#m1-GCC-curunitper').text("4");
    $('#m1-GCC-rtugal').text("260");
    $('#m1-GCC-listprice').val("94.80");
    $('#m1-GCC-rtugalcost').text("0.36");
    $("select[name='genpname'] option").remove();
    $("<option />").val("NF-ND").text("NeutraFect").appendTo($genpname);
    $('#m1-GCC-gendilrate').text("64");
    $('#m1-GCC-genunitper').text("4");
    $('#m1-GCC-genrtugal').text("260");
    $('#m1-GCC-genprice').val("76.36");
    $('#m1-GCC-genrtugalcost').text("0.29");
    
      };
      
    if ($(this).val() == "quat256") {
    $('#m1-GCC-dilrate').text("256");
    $('#m1-GCC-curunitper').text("4");
    $('#m1-GCC-rtugal').text("1028");
    $('#m1-GCC-listprice').val("157.25");
    $('#m1-GCC-rtugalcost').text("7.31");
    $("select[name='genpname'] option").remove();
    $("<option />").val("HF-FFD").text("HyperFect 256").appendTo($genpname);
    $('#m1-GCC-gendilrate').text("256");
    $('#m1-GCC-genunitper').text("4");
    $('#m1-GCC-genrtugal').text("1028");
    $('#m1-GCC-genprice').val("163.33");
    $('#m1-GCC-genrtugalcost').text("0.16");
    
      };
      
    if ($(this).val() == "Term") {
    $('#m1-GCC-dilrate').text("64");
    $('#m1-GCC-curunitper').text("4");
    $('#m1-GCC-rtugal').text("260");
    $('#m1-GCC-listprice').val("140.64");
    $('#m1-GCC-rtugalcost').text("0.54");
    $("select[name='genpname'] option").remove();
    $("<option />").val("GF-AD").text("GeneFect").appendTo($genpname);
    $('#m1-GCC-gendilrate').text("64");
    $('#m1-GCC-genunitper').text("4");
    $('#m1-GCC-genrtugal').text("260");
    $('#m1-GCC-genprice').val("85.38");
    $('#m1-GCC-genrtugalcost').text("0.33");
    
      };
      
    if ($(this).val() == "Mar") {
    $('#m1-GCC-dilrate').text("64");
    $('#m1-GCC-curunitper').text("4");
    $('#m1-GCC-rtugal').text("260");
    $('#m1-GCC-listprice').val("118.94");
    $('#m1-GCC-rtugalcost').text("0.46");
    $("select[name='genpname'] option").remove();
    $("<option />").val("OP-PC").text("OxyPure").appendTo($genpname);
    $('#m1-GCC-gendilrate').text("64");
    $('#m1-GCC-genunitper').text("4");
    $('#m1-GCC-genrtugal').text("260");
    $('#m1-GCC-genprice').val("141.93");
    $('#m1-GCC-genrtugalcost').text("0.55");
    
      };
      
    
    $newcurcostrtu = $('#m1-GCC-rtugalcost').text()*1;
    $gencostrtu = $('#m1-GCC-genrtugalcost').text()*1;
    $value=(Math.round((($newcurcostrtu-$gencostrtu)*100))/100);
      
    $('#m1-GCC-savings').text($value.toFixed(2));
    
    phoneui.preprocessDOM('#m1-GCC');
    
    
    #341769

    Hi dannyg280,

    A couple thoughts:

    function.productname() { code in here};

    1) Are you using this dot in your function? if yes, it must be causing an sintax error and that would be why your code is not being executed.

    2) Could you confirm that the function you are calling on the onChange action is being fired? i.e. commenting all the code and adding an alert instruction. If the alert is shown, then the syntax error is in the code within the function.

Viewing 2 posts - 1 through 2 (of 2 total)
Reply To: Best way to use static data in function? Newbie Warning! :)

You must be logged in to post in the forum log in