...

# Minimum value needed

Richard Welch
05-07-2008, 04:45 PM
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

nottRobin
05-07-2008, 04:47 PM
Couldn't you just add if(total < 9) {total = 9};?

Richard Welch
05-07-2008, 05:18 PM
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);
}