# Solved: JAVASCRIPT: Not working in firefox



## sepala (May 20, 2010)

The following code is for JAVASCRIPT calculator. But the problem is, it is not working on firefox. I think I have to use getElementByID, but I really don't know where to apply it. please help.


```
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Untitled Document

[CENTER]

[B][SIZE=15]Online Calculator[/SIZE][/B]

First Number: 
Second Number:

   
   
   

Your Result is:[/CENTER]
```


----------



## andythepandy (Jul 2, 2006)

The way you are using to find the 2 textboxes and the result div, i.e. using txt1.value, works when addressing the elements id, not their name. So for your current code to work, change the 2 textboxes names to ids.
You should however use document.getElementById('id') though like you say.
That does exactly what it says, it gets the element with the given id - So, if your textbox had an id of 'txt1', to you would use

```
document.getElementById('txt1').value
```
to get its value

Read http://www.w3schools.com/jsref/met_doc_getelementbyid.asp from more

There is also document.getElementsByName('name') - http://www.w3schools.com/jsref/met_doc_getelementsbyname.asp


----------



## sepala (May 20, 2010)

Hi Andy,
I edited my script, but still it is not working.


```
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Untitled Document

[CENTER]

[B][SIZE=15]Online Calculator[/SIZE][/B]

First Number: 
Second Number:

   
   
   

Your Result is:[/CENTER]

/CODE]
```


----------



## andythepandy (Jul 2, 2006)

Thats working for me, what browser are you using?


----------



## sepala (May 20, 2010)

Firefox!!


----------



## andythepandy (Jul 2, 2006)

Well, I just tested it and it works


----------



## sepala (May 20, 2010)

It works in google Chrome!! Both are using Netscape Technology right?


----------



## sepala (May 20, 2010)

I browsed the internet and it says some times we have to clear Firefox cache, in a matter like this. I am going to check it now..


----------



## andythepandy (Jul 2, 2006)

I think that's the problem I just had, and I was running the older version. Sorry, you also need a getElementById on the results bit:

```
document.getElementById('result').innerHTML = "<center>"+num3+"</center>";
```


----------



## sepala (May 20, 2010)

Thanks andy, now it works. Thank you so much...


----------

