• Hey, guest user. Hope you're enjoying NeoGAF! Have you considered registering for an account? Come join us and add your take to the daily discourse.

Dreamweaver/Javascript help

Status
Not open for further replies.

jonhuz

Member
I'm trying to setup some script that once a value is entered, it calculates a value based on a sliding scale.

Example:
0-50 = £55
51-100 =£50
101-200 = £40

So if 50 entered as value it would multiple by a value of 55 and give a sub total, 76 by a value of 50.
I've setup the basic multiple value by 55, but unsure how to setup if less than 50 use this, if greater than or equal to 51 use this value arguement.

This is the code dreamweaver produces for what i've got so far:

function KW_getVal(o){ //v1.2
var retVal="0";if (o.type=="select-one")
{retVal=(o.selectedIndex==-1)?0:eek:.options[o.selectedIndex].value;}
else if (o.length>1){for (var i=0;i<o.length;i++) if (o.checked) retVal=o.value;
} else if (o.type=="checkbox") {retVal=(o.checked)?o.value:0;} else {
retVal=Number(o.value)}return parseFloat(retVal);
}

function KW_calcForm() { //v1.2
var str="",a=KW_calcForm.arguments; for (var i=3;i<a.length;i++)
str+=(a.indexOf("#")==-1)?a:KW_getVal(MM_findObj(a.substring(1)));
t=Math.round(a[1]*eval(str))/a[1];tS=t.toString();if(a[2]>0){tSp=tS.indexOf(".");
if(tSp==-1) tS+=".";tSp=tS.indexOf(".");while(tSp!=(tS.length-1-a[2])){tS+="0";
tSp=tS.indexOf(".");}} MM_findObj(a[0]).value=tS;
}
//-->


<th height="40" bordercolor="#000000" bgcolor="#99CCFF" scope="row"><div align="left" class="position2">* Core Key Skills Sport &pound;55.00: </div></th>
<td valign="top" bgcolor="#99CCFF"><input name="core" type="text" id="core" onChange="KW_calcForm('coresub',100,2,'#core,'*','55')" value="0" size="3">

I know the code is messy (dreamweaver), but i've no idea how to write javascript. Any suggestions?
 
Status
Not open for further replies.
Top Bottom