/    Sign up×
Community /Pin to ProfileBookmark

Form Calculator Help

Hi, I am working on inserting a new selection into a form which uses Javascript to calculate totals.

Here is the code for the top of the page:

[CODE]<script type=”text/javascript”>
<!–
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf(“?”))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function KW_getVal(o){ //v1.2
var retVal=”0″;if (o.type==”select-one”)
{retVal=(o.selectedIndex==-1)?0:o.options[o.selectedIndex].value;}
else if (o.length>1){for (var i=0;i<o.length;i++) if (o[i].checked) retVal=o[i].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[i].indexOf(“#”)==-1)?a[i]:KW_getVal(MM_findObj(a[i].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;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}
//–>
</script>[/CODE]

Here is the code contained within the form:

[CODE]<tr>
<td><span class=”item_title”Logo Sticker</span> (min. order 100) <img src=”images/0_pic.gif” border=”0″ onclick=”MM_openBrWindow(‘images/orderform/ogo_sticker.gif’,”,’scrollbars=yes,resizable=yes,width=400,height=550′)” /> </td>
<td width=”178″>$4.00<br />
per 100</td>
<td ><select name=”Logo_Decals_MEMB_A0_006″ id=”cpa_logo_stickers” onchange=”Calc(this.form);”>
<option value=”0″> </option>
<option value=”100″>100</option>
<option value=”200″>200</option>
<option value=”300″>300</option>
<option value=”400″>400</option>
<option value=”500″>500</option>
<option value=”600″>600</option>
<option value=”700″>700</option>
<option value=”800″>800</option>
<option value=”900″>900</option>
<option value=”1000″>1000</option>
<option value=”1100″>1100</option>
<option value=”1200″>1200</option>
<option value=”1300″>1300</option>
<option value=”1400″>1400</option>
<option value=”1500″>1500</option>
<option value=”1600″>1600</option>
<option value=”1700″>1700</option>
<option value=”1800″>1800</option>
<option value=”1900″>1900</option>
<option value=”2000″>2000</option>
</select></td>
<td width=”88″>$
<input id=”Logo_Decals_Amount” type=”text” name=”Logo_Decals_Amount” value=”” size=”3″ maxlength=”10″ onchange=”Calc(this.form);” /></td>
</tr>[/CODE]

I know that this is not the proper code, it is copied from another form that uses a different Javascript. What code would I need to insert to make it work here?

I have a sample of working code that is used for an item which costs $1.00 and has no drop down selector:

[CODE]<tr>
<td><span class=”item_title-blue”>Envelope &ndash; Individual</span> <img src=”images/0_pic.gif” alt=”Click to See Picture of Item” border=”0″ onclick=”MM_openBrWindow(‘images/orderform/env.jpg’,”,’scrollbars=yes,resizable=yes,width=408,height=547′)” /></td>
<td align=”center” valign=”middle”>$1.00 </td>
<td align=”center” ><p>
<input name=”Envelope” type=”text” id=”FormsEditField224″ onchange=”KW_calcForm(‘Envelope Total’,100,2,’#Envelope’,’*’,’1′)” value=”” size=”4″ maxlength=”4″ />
<label>
<div align=”left”>
</label></td>
<td align=”center”><p>
<input id=”FormsEditField225″ type=”text” name=”Envelope Total” value=”” size=”9″ maxlength=”10″ onfocus=”this.blur()”/>
</p></td>
</tr>
<tr>[/CODE]

The above code does run correctly, I just need it to be for a 4.00 per 100 drop down list as demonstrated before.

Thanks for any help in advance.

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@trmptgnauthorNov 10.2010 — I had it working for a brief time but it has gone back to not working. Again, any help is appreciated.

The javascript is from the Koasweaver Form Calculator extension. More info here http://www.kaosweaver.com/extensions/details.php?id=28.

[CODE]<script type="text/javascript">
<!--
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function KW_getVal(o){ //v1.2
var retVal="0";if (o.type=="select-one")
{retVal=(o.selectedIndex==-1)?0:o.options[o.selectedIndex].value;}
else if (o.length>1){for (var i=0;i<o.length;i++) if (o[i].checked) retVal=o[i].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[i].indexOf("#")==-1)?a[i]:KW_getVal(MM_findObj(a[i].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;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}
//-->
</script>[/CODE]


That is the code at the top of the page.

Below is what is in the table:

[CODE]<td bgcolor="#F4F4F4" align="center">

<select name="Logo Sticker" id="Logo Sticker" onchange="KW_calcForm('Logo Sticker Total',100,2,'#Logo Sticker','*','.04')" />
<option value="0"></option>
<option value="100">100</option>
<option value="200">200</option>
<option value="300">300</option>
<option value="400">400</option>
<option value="500">500</option>
<option value="600">600</option>
<option value="700">700</option>
<option value="800">800</option>
<option value="900">900</option>
<option value="1000">1000</option>
<option value="1100">1100</option>
<option value="1200">1200</option>
<option value="1300">1300</option>
<option value="1400">1400</option>
<option value="1500">1500</option>
<option value="1600">1600</option>
<option value="1700">1700</option>
<option value="1800">1800</option>
<option value="1900">1900</option>
<option value="2000">2000</option>
</select>
</td>
<td width="102" align="center" bgcolor="#F4F4F4">
<input id="Logo Sticker" type="text" name="Logo Sticker Total" value="" size="9" maxlength="10" onfocus="this.blur()"/>
</td>[/CODE]


Again, this worked a couple hours ago but has recently stopped again. Any help is appreciated.
×

Success!

Help @trmptgn spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...