Question:

Javascript code doesn't work in Firefox but works in IE

by  |  earlier

0 LIKES UnLike

Here's my code... It works great in IE but for some reason doesn't work in firefox. Can anyone help me? Thanks!

<script language=javascript>

function cal()

{

var n=frm.txt.value;

var r=frm.txt1.value;

if(n=="" || r=="")

{

alert("Please Enter proper values");

frm.txt2.value="";

}

else

{

var f=1;

for(var i=1;i<=n;i )

{

f=f*i;

}

var r1=n-r;

var res=1;

for(i=1;i<=r1;i )

{

res=res*i;

}

var res1=f/res;

frm.txt2.value=Math.pow(n,r)

}

}

function isInteger(s)

{

var i;

s=s.toString(s);

for(i=0;i<s.length;i )

{

var c=s.charAt(i);

if(isNaN(c))

{

alert("Given value is not a number");

frm.txt.value="";

return false;

}

}

return true;

}

function isInteger1(s)

{

var i;

s=s.toString(s);

for(i=0;i<s.length;i )

{

var c=s.charAt(i);

if(isNaN(c))

{

alert("Given value is not a number");

frm.txt1.value="";

return false;

}

}

return true;

}

</script>

Here's my form in case it helps with troubleshooting...

<form name="frm">

<table style="border:solid green 1px">

<tr><td>Enter the value of n</td>

<td><input type=text name="txt" size=12 onKeyup="isInteger()"></td></tr>

<tr><td>Enter the value of r</td>

<td><input type="text" name="txt1" size=12 onKeyup="isInteger1()"></td></tr>

<tr><td>The Result</td>

<td><input type="text" name="txt2" size=12 READONLY></td></tr>

<tr><td align=right><input type="button" value="Find" onclick="cal()"></td><td></td></tr>

<tr><td></td><td align=center>©<a href="http://www.hscripts.com" style="color:#3D366F;text-decoration:non...

</table>

</form>

 Tags:

   Report

5 ANSWERS


  1. Works sweet in MSIE? You&#039;ve gotta be kidding. The for loops are improperly written: since they are not incremented or decremented, they don&#039;t loop, hence you have written an unresponsive script - not only for Firefox, but for MSIE and any other browser, besides - I tried your script in both browsers and neither one returned a result, rather they returned a dialog about an unresponsive script - sound familiar? And as the other poster mentioned, yes, you should be using document.getElementById(&#039;yourElementName... instead of your method; frm.txt.value is more correctly written as document.frm.txt.value, but the fact is that it has been deprecated in favor of getElementById. The HTML you are using is semantically incorrect, not to mention invalid.  Tables for non-tabular data is a coding style that went out of vogue 6 years ago, but even if today was 6 years ago, you need to know that element attributes are always in quotes in well formed HTML docs (reference your size and type attributes). Fix the for loops and try again.


  2. Make sure you have your javascript turned on.  Sometimes that is the only problem. =]

    Hope this helped!

  3. I think you should not use getElementById instead of directly linking to tags in your code.

    http://www.w3schools.com/HTMLDOM/met_doc...

    Anyways I think you also should take a look at the error console in Firefox. It may help you solve the problem.

    Hope this helps!

  4. maybe you have to download soemthing

  5. I highly recommend downloading the web developer toolbar for Firefox, it&#039;s a life saver.  It will tell you any errors with the CSS or Javascript along with what line the error is on.  It also has tons of other useful features that help with developing web pages.  Try it out:

    https://addons.mozilla.org/en-US/firefox...

Question Stats

Latest activity: earlier.
This question has 5 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.
Unanswered Questions