homepage Welcome to WebmasterWorld Guest from 54.225.57.156
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / WebmasterWorld / New To Web Development
Forum Library, Charter, Moderators: brotherhood of lan & mack

New To Web Development Forum

    
Adding + $1 for every 1 quanitity, 3 qty = +$3
Using Javascript for Checkout Form...
isaaclloyd




msg:964953
 12:42 am on Mar 22, 2005 (gmt 0)

I am using this script to update a total cost text box at the end of my form. Here is the cost format script:


<SCRIPT LANGUAGE="JavaScript">

<!-- Begin
function CheckChoice(whichbox)
{
with (whichbox.form)
{
//Handle differently, depending on type of input box.
if (whichbox.type == "radio")
{
//First, back out the prior radio selection's price from the total:
hiddentotal.value = eval(hiddentotal.value) - eval(hiddenpriorradio.value);
//Then, save the current radio selection's price:
hiddenpriorradio.value = eval(whichbox.price);
//Now, apply the current radio selection's price to the total:
hiddentotal.value = eval(hiddentotal.value) + eval(whichbox.price);
}
else
{
//If box was checked, accumulate the checkbox value as the form total,
//Otherwise, reduce the form total by the checkbox value:
if (whichbox.checked == false)
{ hiddentotal.value = eval(hiddentotal.value) - eval(whichbox.value); }
else { hiddentotal.value = eval(hiddentotal.value) + eval(whichbox.value); }
}

//Ensure the total never goes negative (some browsers allow radiobutton to be deselected):
if (hiddentotal.value < 0)
{
InitForm();
}

//Now, return with formatted total:
return(formatCurrency(hiddentotal.value));
}
}

//Define function to format a value as currency:
function formatCurrency(num)
{
num = num.toString().replace(/\$\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(1,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + '$' + num + '.' + cents);
}

//Define function to init the form on reload:
function InitForm()
{
//Reset the displayed total on form:
document.myform.total.value='$0';
document.myform.hiddentotal.value=0;
document.myform.hiddenpriorradio.value=0;

//Set all checkboxes and radio buttons on form-1 to unchecked:
for (xx=0; xx < document.myform.elements.length; xx++)
{
if (document.myform.elements[xx].type == 'checkbox' document.myform.elements[xx].type == 'radio')
{
document.myform.elements[xx].checked = false;
}
}

}

// End -->
</script>

What I am trying to figure out is when I click this box, I need it to add the value to the total amount using the part of the script above but also add +$1 (1.00) for every quantity of items. So if the value in the QTY text box is: 5 then when this box is clicked add $10 + $5.


<input type=text name="quantity" size=3 value=0 priorval=0 price="109.00" onChange="this.form.total.value=checkChoice(this);">

$10 Shipping: <input type="checkbox" name="$10_shipping" value=10.00 onclick="countChoices(this);" onChange="this.form.ship_method.value=this.name;" onpropertychange="this.form.total.value=CheckChoice(this);">

TOTAL: <input type="text" name="total" value="" size=8 readonly onFocus="this.blur();">

Any comments or suggestions are greatly apreciated.
Thanks.

~Isaac Lloyd~

 

MichaelBluejay




msg:964954
 9:13 am on Mar 25, 2005 (gmt 0)

I'd suggest posting this (and the other post) in the Javascript forum.

Sorry I'm not offering to help with these, the code is too long and I have a short attention span. :)

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / WebmasterWorld / New To Web Development
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved