There are a few things that are just wrong as you will soon see.
First of all, there are many ways to retrieve the value from a form field using Javascript. As the button you clicked is still part of the form, you could refer to the price field value by
this.form.price.value (this.form is a reference to the form. Every named field is a property of this form element and .value is the value property of this element)
Code:
<input type="button" value="View Total" onclick="ship_hand(this.form.price.value)" />
Your function ship_hand() doesn't look that bad, but
- You must not define a new
var price inside your function because you are already passing a defined "price" variable as a parameter. A new definition would overwrite the passed parameter
- The value of a form field is always of type String. So the first thing you need to do if you want to use it for calculation or for comparison with numeric values is to convert it to a number
- You are using string concatenation wrong inside your alert() methods
Code:
function ship_hand (price) {
price = parseFloat(price);
var min_fee = 1.50;
var max_fee = (price * 10 / 100);
if ( price <= 25.00)
window.alert ( price + min_fee);
else
window.alert ( price + max_fee);
}