close ad
Install the LAtest Updates to Work with CC 2017 and CC 2018
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

if, else statement not sure why it's not working

Thread began 9/03/2013 11:23 am by tdhkfinkel424121 | Last modified 9/03/2013 2:38 pm by Jason Byrnes | 556 views | 3 replies |

tdhkfinkel424121

if, else statement not sure why it's not working

Hi,
I'm trying to break my problem down to smaller bit and I thought an if..else statement (or in this case if..if.. because I keep getting an error with if..else in my dreamweaver program) would help but it's not working...


<script language="javascript">

function processSubTotalA()
{
var quantity = parseInt(document.MarinaServices.txtLOA.value);
var unitPrice = parseFloat(document.MarinaServices.txtMoorPrice.value);
var subTotalA = unitPrice * quantity;
if(quantity <30);
{
(isFlatRate = true);
(flatRate = 1599);
(flatRate = unitPrice);
(flateRate = subTotalA);
}
if(quantity >30);
{
(isPerFoot = true);
(unitPrice = 55);
(perFoot = unitPrice);
(subTotalA = unitPrice * quantity);
}

document.MarinaServices.txtServiceASubTotal.value = serviceASubTotal.toFixed(2);
}


function calculateTaxAmount(price, tax)
{
var amount = price * tax / 100;
return amount;
}

function processMoor()
{
var MoorTotal;

var subTotalB = parseFloat(document.MarinaServices.txtServiceASubTotal.value);

var subTotalB = subTotalA;
var taxRate = parseFloat(document.MarinaServices.txtTaxRate.value);
var taxAmount = calculateTaxAmount(serviceBSubTotal, taxRate);
var moorTotal = serviceBSubTotal + taxAmount;

document.MarinaServices.txtServiceBSubTotal.value = serviceBSubTotal.toFixed(2);
document.MarinaServices.txtTaxAmount.value = taxAmount.toFixed(2);
document.MarinaServices.txtMoorTotal.value = moorTotal.toFixed(2);
}

</script>
<script language="javascript">
function processServiceASubTotal()
{
var unitPrice = parseFloat(document.MarinaServices.txtMoorPrice.value.value);
var quantity = parseInt(document.MarinaServices.txtLOA.value);
var subTotalA = unitPrice * quantity;

if(quantity <30);
{
(isFlatRate = true);
(flatRate = 1599);
(flatRate = unitPrice);
(flateRate = subTotalA);
}
if(quantity >30);
{
(isPerFoot = true);
(unitPrice = 55);
(perFoot = unitPrice);
(subTotalA = unitPrice * quantity);
}

document.MarinaServices.txtMoorPrice.value = moorPrice.toFixed(2);
document.MarinaServices.txtServiceASubTotal.value = serviceASubTotal.toFixed(2);
}

function calculateTaxAmount(price, tax)
{
var amount = eval(price * tax / 100);
return amount;
}

function processMoorTotal()
{
var SubTotalA;

var subTotalA = parseFloat(document.MarinaServices.txtServiceASubTotal.value);

var subTotalB = eval(subTotalA);
var taxRate = parseFloat(document.MarinaServices.txtTaxRate.value);
var taxAmount = calculateTaxAmount(subTotalB, taxRate);
var moorTotal = eval(subTotalB + taxAmount);

document.MarinaServices.txtServiceBSubTotal.value = serviceBSubTotal.toFixed(2);
document.MarinaServices.txtTaxAmount.value = taxAmount.toFixed(2);
document.MarinaServices.txtMoorTotal.value = moorTotal.toFixed(2);
}

</script>

</head>

<body>
<table width="800" border="0" cellspacing="0" cellpadding="0">
<div id="wrap">
<form action="" id="MarinaServices" name="MarinaServices" onsubmit="return false,">
<tr>
<th scope="col"><table width="100%" border="0">
<tr>
<td align="left" nowrap="nowrap"><label for="SUMMER_Moor_LOA_Boat" class="sublabel"> <strong>Summer Mooring:</strong><br />
May 1- Oct.31</label></td>
<td align="left"> <span class="style59">*</span>
<input id="txtLOA" input="input" name="txtLOA" type="text" class="formTextfield_XSmall" value="<?php echo((isset($_GET["invalid"])?ValidatedField("MarinaServices","txtLOA"):"")); ?>" size="4" tabindex="33" onblur="hideServerError('txtLOA_ServerError');" />

Ft. LOA</td>
<td><span class="style59">*</span> $
<input id="txtMoorPrice" input="input" name="txtMoorPrice" type="text" class="formTextfield_XSmall" value="<?php echo((isset($_GET["invalid"])?ValidatedField("MarinaServices","txtMoorPrice"):"")); ?>" size="11" tabindex="34" onblur="hideServerError('txtMoorPrice_ServerError');" />
/ft</td>
<td><input name="btnMoor" type="button" onclick="processMoor()" value="Calc." tabindex="35" /></td>
<td>Sub Total $
<input type="text" name="txtServiceASubTotal" class="formTextfield_Small" size="8" value="0.00" tabindex="36" /></td>
</tr>
</table>
<table width="100%" border="0">
<tr>
<td>&nbsp;</td>
<td colspan="5"><input name="btnCalculate" type="button" onclick="processMoor()" value="Calc. Tax/Total" tabindex="37" /></td>
</tr>
<tr>
<td colspan="2" >Sub Total:$
<input name="txtServiceBSubTotal" type="text" class="formTextfield_Small" value="0.00" size="8" tabindex="38" /></td>
<td>Tax Rate</td>
<td><input name="txtTaxRate" type="text" class="formTextfield_XSmall" value="6.25" size="5" tabindex="39" />
%</td>
<td>Tax Amount:$
<input name="txtTaxAmount" type="text" class="formTextfield_Small" value="0.00" size="8" tabindex="40" /></td>
<td>Mooring Total: $
<input name="txtMoorTotal" type="text" class="formTextfield_Small" value="0.00" size="8" tabindex="41" /></td>
</tr>
</table>
<table width="100%" border="0">
<tr> </tr>
</table>
</form>
</div>
</th>
</tr>
</table>
</script>
</body>
</html>

I'm only working on the top section of this form.
And yes I did request one on one help session, but if you could look at this in the mean time I would be greatful.
Thanks

Sign in to reply to this post

Jason ByrnesWebAssist

I need more details.

What is it you are trying to do?

What specific code is it on this page that is not working?

What is it supposed to do?

What does it do instead?

Sign in to reply to this post

tdhkfinkel424121

Oop Sorry

Hi Jason,

Sorry I guess I forgot the explanation...
What I'm working on is creating an 'if...,else' statement for the MoorPrice.
If the value entered in the LOA text box is less than 30 then the MoorPrice & subtotal should be 1599
If the value entered in the LOA text box is more than (or equal to) 30 then the MoorPrice should be 55 and the calculation for the subtotal should be
subTotalA = unitPrice(MoorPrice) * quantity(LOA)

The rest of the calculations of that part of the form stay as is.

Instead of doing the above it does nothing, no calculations at all.

Sign in to reply to this post

Jason ByrnesWebAssist

i'm still pretty confused as the calc button in the top line calls the processMoor() function and that function has a number of syntax issues, the worst of which is this line:
var moorTotal = serviceBSubTotal + taxAmount;

using a variable that does not exist:
serviceBSubTotal



there is subTotalB, but no serviceBSubTotal.


in other areas< you have code for the if statement:
if(quantity <30);
{
(isFlatRate = true);
(flatRate = 1599);
(flatRate = unitPrice);
(flateRate = subTotalA);
}


that is wrong for a number of reasons:
a) no semi colon after the if statement
b) the open bracket should be on the same line as the if:

if(quantity <30) {

c) You redefine twice

(flatRate = 1599);
(flatRate = unitPrice);
(flateRate = subTotalA);

d) no parens are needed around setting flat rate:
flatRate = 1599;


the format of the if else statement should be:
if(quantity <30) {
do something
} else {
do something else
}

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...