Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

javascript form not working in firefox

Status
Not open for further replies.

neomas

Technical User
May 15, 2007
3
TH
The script works fine in IE and Safari, but I get no response from Firefox.I don't know what's wrong.

Code is as follows:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874" />
<title>Untitled Document</title>
<script type="text/javascript">
function updateprice()
{
var A_price=0;
var B_price=0;
var amount_price=0;
var amount_A=0;
var amount_B=0;

registertype=(autoSumForm.registertype.value);
switch (registertype) {
case "dh" :
A_year=(autoSumForm.A_year.value);
cost_A=(autoSumForm.cost_A.value);
amount_A=A_year*cost_A;

month=(autoSumForm.B_month.value);
B_price=(autoSumForm.B_plan.value);
amount_B=B_price*month;
break;

case "d" :
A_year=(autoSumForm.A_year.value);
cost_A=(autoSumForm.cost_A.value);
amount_A=A_year*cost_A;
break;

case "h" :
month=(autoSumForm.B_month.value);
B_price=(autoSumForm.B_plan.value);
amount_B=B_price*month;
break;
}

/*
A_year=(autoSumForm.A_year.value);
cost_A=(autoSumForm.cost_A.value);
amount_A=A_year*cost_A;

month=(autoSumForm.B_month.value);
B_price=(autoSumForm.B_plan.value);
amount_B=B_price*month;
*/
amount_price=amount_A+amount_B;
autoSumForm.price.value=amount_price;
}
// End -->
</script>
</head>

<body>
<form name="autoSumForm">
<p>
<input name="registertype" type="hidden" value="dh" />
Price A
<input name="cost_A" value="450" size="7" />
USD/Year
<select name="A_year" size="1" onChange="updateprice();">
<option value="0" selected="selected">Select</option>
<option value="1">1 year</option>
<option value="2">2 years </option>
<option value="3">3 years </option>
</select>
+ Price B
<select name="B_plan" onChange="updateprice();">
<option value="">Select</option>
<option value="80">Plan A = 80 USD/year</option>
<option value="150">Plan B = 150 USD/year</option>
<option value="500">Plan C = 500 USD/year</option>
</select> <select name="B_month" onChange="updateprice();">
<option value="">Select</option>
<option value="12">1 year</option>
<option value="24">2 years</option>
</select><br />
= <input name="price" type="text" />

</p></form>

</body>
</html>

or see
Thanks you.
 
To remove any warnings in FF, give your elements IDs instead of names and reference them with
Code:
document.getElementById("id")

What I find weird is that your code worked fine on my desktop (besides the warnings), but didn't work on your site.

[monkey][snake] <.
 
feherke didn't mean to only change that once instance - you changed the line that (s)he pointed out, and now the error has moved to line 18:
Code:
A_year=(autoSumForm.A_year.value);

Everywhere you are referencing a form, you need to add document before it. In all honesty, you should get away from document.form.element syntax - it's confusing and outdated. Use document.getElementById like monksnake pointed out, or use the forms and elements collections:
Code:
document.forms["[!]formName[/!]"].elements["[!]elementName[/!]"]

Using the forms and elements collections leaves no ambiguity in your code about what you are trying to access. (compared to methods and properties specifically)

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson
 
OK thank you very much for feherke , monksnake, and kaht.
the code worked on fire fox.

registertype=(document.autoSumForm.registertype.value);
switch (registertype) {
case "dh" :
A_year=(document.autoSumForm.A_year.value);
cost_A=(document.autoSumForm.cost_A.value);
amount_A=A_year*cost_A;

month=(document.autoSumForm.B_month.value);
B_price=(document.autoSumForm.B_plan.value);
amount_B=B_price*month;
break;

case "d" :
A_year=(document.autoSumForm.A_year.value);
cost_A=(document.autoSumForm.cost_A.value);
amount_A=A_year*cost_A;
break;

case "h" :
month=(document.autoSumForm.B_month.value);
B_price=(document.autoSumForm.B_plan.value);
amount_B=B_price*month;
break;
}

/*
A_year=(document.autoSumForm.A_year.value);
cost_A=(document.autoSumForm.cost_A.value);
amount_A=A_year*cost_A;

month=(document.autoSumForm.B_month.value);
B_price=(document.autoSumForm.B_plan.value);
amount_B=B_price*month;
*/
amount_price=amount_A+amount_B;
document.autoSumForm.price.value=amount_price;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top