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!

Script Doesn't Work In Firefox

Status
Not open for further replies.

dodge20

MIS
Jan 15, 2003
1,048
US
Will Someone help me change my javascript so it will work in all browsers? It works in IE, but not Firefox. Thanks

Code:
<SCRIPT language="JavaScript">
var total = 0;
function anyCheck(form) {
var max = form.ckbox.length;
for (var idx = 0; idx < max; idx++) {
if (eval("document.form1.ckbox[" + idx + "].checked") == true) {
    total += 1;
   }
}
}
function Calculate()
{
if (form1.txtSize.value >= 1)
	form1.txtTotal.value = 5.00 * form1.txtSize.value + (total * 3)
if (form1.txtSize.value > 10)
	form1.txtTotal.value = 4.80 * form1.txtSize.value + (total * 3)
if (form1.txtSize.value > 25)
	form1.txtTotal.value = 4.60 * form1.txtSize.value + (total * 3)
if (form1.txtSize.value > 50)
	form1.txtTotal.value = 4.50 * form1.txtSize.value + (total * 3)
if (form1.txtSize.value > 100)
	form1.txtTotal.value = 4 * form1.txtSize.value + (total * 3)
else 0
total=0;
}
function ChangeVal(txtTotal)
{
    TheVal=txtTotal.value
    TheVal=TheVal.replace("$","")
    if(TheVal!="")
    {
        if(TheVal.indexOf(".")!=-1)
        {
            if(TheVal.match(/\.\d$/))
            {
                TheVal=TheVal+"0"
            }
        }
        else
        {
            TheVal=TheVal+".00"
        }
    }
    txtTotal.value="$"+TheVal
}

</script>

Code:
<form name="form1" method="post" action="">
              <table width="500" border="1" align="center" cellpadding="2" cellspacing="2">
                <tr>
                  <td colspan="2" align="right" valign="top"><div align="center">
                    <h3>Price Calculator </h3>
                  </div></td>
                </tr>
                <tr>
                  <td align="right" valign="top">Enter Number of GB:</td>
                  <td><input name="txtSize" type="text" id="txtSize" size="8" maxlength="3"></td>
                </tr>
                <tr>
                  <td align="right" valign="top"><p>Choose the modules<br>
                    you would like to add:</p>
                  </td>
                  <td><input name="ckbox" type="checkbox" id="ckbox" value="checkbox">
                  Microsoft Exchange Server <br>
                  <input name="ckbox" type="checkbox" id="ckbox" value="checkbox">
                  Microsoft SQL Server <br>
                  <input name="ckbox" type="checkbox" id="ckbox" value="checkbox">
                  Oracle Database Server <br>
                  <input name="ckbox" type="checkbox" id="ckbox" value="checkbox">
                  Lotus Notes/Domino <br>
                  <input name="ckbox" type="checkbox" id="ckbox" value="checkbox">
                  MySql Database Server </td>
                </tr>
                <tr>
                  <td align="right" valign="top">&nbsp;</td>
                  <td><input type="button" name="Button" value="Calculate" 
				  		onClick="anyCheck(this.form), Calculate(), ChangeVal(txtTotal);"></td>
                </tr
                ><tr>
                  <td align="right" valign="top">Monthly Fee: </td>
                  <td><input name="txtTotal" type="text" id="txtTotal" size="15"></td>
                </tr>
              </table>
            </form>

Dodge20
 
looks like i needed to add the word document infront of all my form1 values.

Dodge20
 
All your checkboxes share the same ID (this shoud be unique for all elements in a page). It will be a good idea to fix that, regardless.

Cheers,
Jeff

[tt]Jeff's Blog [!]@[/!] CodeRambler
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
Best advice I would give to you is to make sure you have the "Firebug" extension for Firefox. This is probably the best script debugging tool I have ever used. You can inspect html page elements and watch variables as well as seeing ajax posts and returns.

Saved me hours of troubleshooting time.



LJ Wilson

My personal saying - Just remember, it can always get worse, and usually will.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top