Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Nov 2006
    Location
    Oxford/Barcelona
    Posts
    47
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Minimum value needed

    Hi,

    Can someone help me with putting in a minimum value for the below code. It is a simple calculation to calculate a quote with 4 variables: words, source, target and type.

    Problem is I need a minimum value, so for 1 word it will give £/$9.00 instead of £/$0.08.

    I had some help originally with the code as Javascript is new to me.

    function workit()
    {
    var xsource = new Array(0,0.09,0.1); // source language
    var xtarget = new Array(0,0.08,0.09); // target language
    var xtype = new Array(0,0,0.06,0,0.02,0.02,0.04,0.03,0.01); // type of text
    var itemA = parseInt(form1.words.value);
    if(!itemA){itemA=1};
    var itemB = parseInt(form1.source.options[form1.source.selectedIndex].value);
    var itemC = parseInt(form1.target.options[form1.target.selectedIndex].value);
    var itemD = parseInt(form1.type.options[form1.type.selectedIndex].value);

    var total = (itemA*(xtarget[itemC]+xtype[itemD]));

    mytotal.innerHTML = total.toFixed(2);
    }

    Thanks to anyone that can help me out,

    Richard

  • #2
    New Coder
    Join Date
    May 2008
    Posts
    12
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Couldn't you just add if(total < 9) {total = 9};?

  • #3
    New Coder
    Join Date
    Nov 2006
    Location
    Oxford/Barcelona
    Posts
    47
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Thanks, it worked.

    if I wanted to have minimum values for one of the variables: type of text, so different types of text would have different minimum values, how would I write that into the code.

    Thanks,

    Richard.

    function workit()
    {
    var xsource = new Array(0,0.09,0.1); // source language
    var xtarget = new Array(0,0.08,0.09); // target language
    var xtype = new Array(0,0,0.06,0,0.02,0.02,0.04,0.03,0.01); // type of text
    var itemA = parseInt(form1.words.value);
    if(!itemA){itemA=1};
    var itemB = parseInt(form1.source.options[form1.source.selectedIndex].value);
    var itemC = parseInt(form1.target.options[form1.target.selectedIndex].value);
    var itemD = parseInt(form1.type.options[form1.type.selectedIndex].value);

    var total = (itemA*(xtarget[itemC]+xtype[itemD]));

    if(total < 9) {total = 9};

    mytotal.innerHTML = total.toFixed(2);
    }


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •