PDA

View Full Version : I have a code in which I am suppose to create a submit button which will calculate



Sied704
Feb 13th, 2012, 04:53 AM
I need this code to calculate the sales tax when you hit the submit button and I can't get it to work. I need to figure out how to connect it to the function. Can someone please point out where I am going wrong? I am very new at this and am woundering what I am doing wrong with my code. This is homework, I am not looking for the answer I just need someone to direct me in the right way.Thanx

Here is my Code: I need this code to calculate the sales tax when you hit the submit button and I can't get it to work. Can someone please point out where I am going wrong?

Code:
<script type="text/javascript">
/*<![CDATA [*/
//Shipping & handling fee



function calculateShipping()
{
var num = new Number(price);
//This will add $1.50 to any purchases that are less than or equal to $25.00.
if (num <= 25){
return 1.5;
//Here 10% will be added to any purchase that is greater than $25.00 but do not inlcude the

$1.50 fee.
} else{
return num * 10 / 100;
}
}
window.alert("Your total is $" + total + ".")

/* ]]> */
</script>
</head>

<body>
<h1>Enter Purchase Price Here</h1>

<script type="text/javascript">
/* <![CDATA[ */

document.write(parseFloat");
if(price <=25.00){var shipping=1.50}
else{var shipping=price*(10/100)};
var total=(price+shipping).toFixed(2);


/* ]]> */
</script>


<form id="btncalcprice" action="submit-form.php">
<input type='text' name='query'>
</form>

<form>
<input type="button" value="Submit" onClick="alert('YOUR total is $'); return true">

</form>
</body>

Co1dFusion
Feb 13th, 2012, 08:02 AM
Did you mean to have two separate forms?

Go to this site (http://www.w3schools.com/JS/js_form_validation.asp)

This is important, and assigns the variable "x" the value of "fname" in "myform". You cann't just assume that x is the form because its called that.


var x=document.forms["myForm"]["fname"].value;


You should change this arround so it matches your form, add in the maths you need to do, put it in a function and then call it from the submit button.

Do you want to submit the form to another .php page or something, or just send up an alert with the shipping cost in it?