...

View Full Version : Getting value from within a frame



Mazmanyan
08-20-2004, 11:32 PM
If I have an order form with frames and the prices of the items in the form are as follows order form (http://members.fortunecity.com/mazmanyan/order.html) . I need to make the total price appear as the quantities are entered but I'm not getting how to get the price (discounted) of the items so that i can calculate it. thanks for your help.

jamescover
08-21-2004, 12:59 AM
If I have an order form with frames and the prices of the items in the form are as follows order form . I need to make the total price appear as the quantities are entered but I'm not getting how to get the price (discounted) of the items so that i can calculate it. thanks for your help.


BEWARE OF POPUPS USING THE POSTED LINK!


This doesn't address all of your issues, but maybe it will get you started:





-james

jamescover
08-21-2004, 01:10 AM
I think the board ate part of my code, so I'm reposting it here:





<script type="text/javascript">
<!--

function calTot(){

var doc = document['oFrm'];
doc['tot'].value = (((doc['val1'].value)/1) + ((doc['val2'].value)/1) + ((doc['val3'].value)/1));
}

//-->
</script>



<form name="oFrm">
Value1:<input name="chkBx1" type="checkbox" onclick="javascript:if(this.checked){this.form['val1'].value='29.99';}else{this.form['val1'].value='';};calTot();"><input name="val1" type="text" readonly />
<br />

Value2:<input name="chkBx2" type="checkbox" onclick="javascript:if(this.checked){this.form['val2'].value='19.99';}else{this.form['val2'].value='';};calTot();"><input name="val2" type="text" readonly />
<br />

Value3:<input name="chkBx3" type="checkbox" onclick="javascript:if(this.checked){this.form['val3'].value='17.99';}else{this.form['val3'].value='';};calTot();"><input name="val3" type="text" readonly />
<br />
Total: <input name="tot" type="text" readonly />
</form>

Willy Duitt
08-21-2004, 04:20 AM
Mazman;

No offense but that form has some serious issues and I would advise not ever using DreamWeaver again... But then again, I have hand coded from the start....

Your biggest problem is that your form was never properly formatted using form names.... Most of your inputs have a common name of textfield and this makes it impossible to loop thru the form elements and target a particular element by name (besides this will likely come back and byte you on the.... when you submit the form. But that is an entirely different matter which I advise not using mailto for).....

Additional problems are that none of your attributes are quoted and tag names should all be in LowerCase. And although these problems do not affect the matter at hand, they should be address ASAP.... Quite frankly, I advise starting over but that can wait until you at least find some joy with getting this attempt to work as intended...;)

Therefore....

I found a way to make your form work as written with minimal changes.... However, unfortunetly the data cells which contain your discounted prices which are used in the calculations do not have an ID thus there was no way to target these data cells to use their value in the calculations.... Therefore you will need to include the unit price in the function call of each item.... Which is not a real problem but besides making it more difficult, you will need to update both the data cell and the function call whenever price changes are made...

I also assumed that you were adding some type of Taxation for Representation or Value Added Tax (whichever it may be) to calculate your Total from your Sub Total.... therefore I used VAT figured at 17.5%..... Thus; Please note the VAT value and the few form ID and NAME changes highlighted in red which I was required to make in the interest of intuitivety....




<script type="text/javascript">
<!--//
function total(item,price){
var isID = document.getElementById;
var input = document.getElementsByTagName('input');
if(item.value.length > 0 && !item.value.match(/^\d+$/)){
alert('Please enter only whole numbers in this field!');
isID(item.id.replace(/qty/i,'total')).value = '$';
isID(item.id).value = '';
isID(item.id).focus();
}
else if(item.value.length == 0 || item.value == ''){
isID(item.id.replace(/qty/i,'total')).value = '$';
}
else{
var itemPrice = isID(item.id.replace(/qty/i,'total'));
itemPrice.value = '$'+((item.value*1)*(price*1)).toFixed(2);
item.style.textAlign = 'right';
}


var tempTotal = 0, VAT = 1.175;
for(var i=0; i<input.length; i++){
var itemTotal = input[i].value.replace(/\$/,'');
if(input[i].type.match(/text/i) && input[i].id.match(/^\d+total$/gi)){
tempTotal += itemTotal*1;
}
}


isID('subTotal').value = '$'+(tempTotal*1).toFixed(2);
var subTotal = isID('subTotal').value.replace(/\$/,'');
isID('orderTotal').value = '$'+(subTotal*1*VAT).toFixed(2);
isID('grandTotal').value = isID('orderTotal').value;


}
//-->
</script>
</head>

<body>
<FORM name=orderform action=mailto:some@hair.com method=post
encType=multipart/form-data>


<TABLE width=640 bgColor=#ffffff border=1>
<TBODY>

<TR>
<TD class=products width=42>
<DIV align=center>ITEM #</DIV></TD>
<TD class=products width=299>
<DIV align=center>ITEM NAME</DIV></TD>
<TD width=60>
<DIV align=center>regular price</DIV></TD>

<TD class=products width=74>
<DIV align=center>15% off sale price</DIV></TD>
<TD width=37>
<DIV align=center>Qty.</DIV></TD>
<TD width=88>
<DIV align=center>Price</DIV></TD></TR>
<TR>

<TD class=products>
<DIV align=center>1</DIV></TD>
<TD class=products>
<DIV align=left>ARS Moisture Recovery</DIV></TD>
<TD>
<DIV align=right>35</DIV></TD>
<TD class=products>

<DIV align=right>
29.75
</DIV>
</TD>
<TD>
<DIV align=center>
<INPUT id=1qty size=3 name=textfield onkeyup="total(this,29.75)">
</DIV></TD>
<TD>

<INPUT id=1total
onFocus="this.blur();"
size=6 value=$ name=textfield >
</TD></TR>
<TR>
<TD class=products>
<DIV align=center>2</DIV></TD>
<TD class=products>
<DIV align=left>Ethte Clay Shampoo 330ml</DIV></TD>
<TD>

<DIV align=right>18</DIV></TD>
<TD class=products>
<DIV align=right>
15.3
</DIV>
</TD>
<TD>
<DIV align=center>
<INPUT id=2qty size=3 name=textfield onkeyup="total(this,15.3)">

</DIV></TD>
<TD>
<INPUT id=2total
onFocus="this.blur();"
size=6 value=$ name=Total>
</TD></TR>
<TR>
<TD class=products height=28>
<DIV align=center>3</DIV></TD>
<TD class=products>

<DIV align=left>Ethte Clay Shampoo 1000ml</DIV></TD>
<TD>
<DIV align=right>46</DIV></TD>
<TD class=products>
<DIV align=right>
39.1
</DIV>
</TD>

<TD>
<DIV align=center>
<INPUT id=3qty size=3 name=textfield onkeyup="total(this,39.1)">
</DIV></TD>
<TD>
<INPUT id=3total
onFocus="this.blur();"
size=6 value=$ name=Total>
</TD></TR></TABLE>


<TABLE width=640 border=1>
<TBODY>
<TR>
<TD width=416><STRONG>Sub Total</STRONG></TD>

<TD width=118>&nbsp;</TD>
<TD width=84>
<INPUT id=subTotal
onFocus="this.blur();"
size=6 value=$ name=subTotal>
</TD></TR>
<TR>
<TD><STRONG>Total</STRONG></TD>
<TD>&nbsp;</TD>
<TD><INPUT id=orderTotal
onFocus="this.blur();"
size=6 value=$ name=orderTotal>
</TD>
</TR>
</TBODY>
</TABLE>


<STRONG>GRAND TOTAL</STRONG>
<INPUT id=grandTotal onFocus="this.blur();" size=6 value=$ name=grandTotal>
<INPUT type=submit value=Submit name=Submit>
<INPUT type=reset value=Reset name=Submit2>
</FORM>




Good Luck...
.....Willy

BTW: I've also attached a text file in the event this board corrupts the code...

jamescover
08-21-2004, 05:02 AM
oops! I was so annoyed by the popups, I didn't even notice the item # field, so, yeah, disregard my example, although, I think it would be easier to use checkboxes for single quantities...



onFocus

...aren't handlers all lower case nowadays?


-james

Willy Duitt
08-21-2004, 05:09 AM
Hmmm;

Don't you have a Popup Blocker James?.....

I visited the page with both IE and Firefox and did not recieve one Popup.... I did not even notice an alert while using the Google Toolbar Popup blocker with IE... But then again, I have flash and activeX disabled.... Perhaps these were flash driven....

.....Willy

Willy Duitt
08-21-2004, 05:09 AM
Ooops...

Sorry for the double post.... My proxy hung so I switched IP's and both must have submitted at the same time.... :eek:

.....Willy

jamescover
08-21-2004, 08:34 AM
Don't you have a Popup Blocker James?.....

Nooooo. I think these are some of the worst apps ever created. If I don't like a site, I won't return. And as I've stated before, Firefox's is especially annoying, since it blocks all popups by default, so that you have to unblock a site, instead of allowing you to choose who to block.


These are the popups I got from this site (I took a quick look, then ran for my life):


FortuneCity Search
Swingers.com
Win a Free IPod
American Singles
Online Poker


The reason why popup blockers were created, no doubt. But just because some people abuse js, I don't want to stigmatize its legitimate use.



-james

jamescover
08-21-2004, 08:45 AM
These are the popups I got from this site (I took a quick look, then ran for my life):

oh, yeah, and Gator, which I especially despise.



-james

Mazmanyan
08-22-2004, 12:59 AM
Thanks for your help. I fixed up a lot of the problems that you mentioned and have it working. I'm still working on it but I'm getting close to having it fully functional. Thanks again.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum