/    Sign up×
Community /Pin to ProfileBookmark

Hosting Price Calculator

I am trying to create an if statement in this calculator that does the following

if(radiobutton1 == selected) {
AddDecimal(((STotal) * 10) / 12);}
else { (AddDecimal(STotal));
}

I am new to javascript and what i have is not working. the radio button names are r1 and r2.

you can see what i have at [URL=http://www.fivecubed.com/web_hosting/estimate.html]http://www.fivecubed.com/web_hosting/estimate.html[/URL]

<SCRIPT LANGUAGE=”JavaScript”>

<!– hide from old browsers –>

var SAmt1 = 0.00,SAmt2 = 0.00,SAmt3= 0.00,SAmt4 = 0.00,SAmt5 = 0.00,SAmt6= 0.00;
var STax = 0.00,SSubTotal = 0.00,STotal = 0.00;
var Item1 =””,Item2 = “”,Item3 = “”,Item4 =””,Item5 = “”,Item6 = “”;
var SShipping = 0;
/*****************
**
Add a decimal point to a number
*
/

function AddDecimal(number) {
var withdecimal = “”;
var num = “” + number;
if (num.length == 0) {
withdecimal += “0”;
} else if (num.length == 1) {
withdecimal += “0.0” + num;
} else if (num.length == 2) {
withdecimal += “0.” + num;
} else {
withdecimal += num.substring(0, num.length – 2);
withdecimal += “.”
withdecimal += num.substring(num.length – 2, num.length);
}
return withdecimal;
}

function compute(form)
{
SAmt1 = Math.round(eval(form.Item1.value * 10));
SAmt2 = Math.round(eval(form.Item2.value *
300));
SAmt3 = Math.round(eval(form.Item3.value * 100));
SAmt4 = Math.round(eval(form.Item4.value *
100));
SAmt5 = Math.round(eval(form.Item5.value * 50));
SAmt6 = Math.round(eval(form.Item6.value *
5));
SShipping = 00;
SShipping = Math.round(SShipping);
SSubTotal =(SAmt1 + SAmt2 + SAmt3 + SAmt4 + SAmt5 + SAmt6 + SShipping);
STotal =SSubTotal + STax;
form.Amt1.value = AddDecimal(SAmt1);
form.Amt2.value = AddDecimal(SAmt2);
form.Amt3.value = AddDecimal(SAmt3);
form.Amt4.value = AddDecimal(SAmt4);
form.Amt5.value = AddDecimal(SAmt5);
form.Amt6.value = AddDecimal(SAmt6);
form.SubTotal.value = AddDecimal(SSubTotal);
form.Total.value = if(r1 == selected) {
AddDecimal(((STotal) * 10) / 12);}
else { (AddDecimal(STotal));
}

}

function ClearForm(form)
{form.Item1.value = “”;
form.Item2.value = “”;
form.Item3.value = “”;
form.Item4.value = “”;
form.Item5.value = “”;
form.Item6.value = “”;

SShipping = 0;
form.Shipping.value = 0;
SSubTotal = 0;
form.SubTotal.value = 0;

SAmt1 = 0;
form.Amt1.value = 0;
SAmt2 = 0;
form.Amt2.value = 0;
SAmt3 = 0;
form.Amt3.value = 0;
SAmt4 = 0;
form.Amt4.value = 0;
SAmt5 = 0;
form.Amt5.value = 0;
SAmt6 = 0;
form.Amt6.value = 0;

SShipping = 0;
form.Shipping.value = 0
SSubTotal = 0;
form.SubTotal.value = 0;
STotal = 0;
form.Total.value = 0;
}
<!– done hiding from old browsers –>
</SCRIPT>

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @fivecubed_com 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.18,
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,
)...