# Solved: JavaScript not working in Mozilla Firefox



## lexicon (Sep 10, 2006)

Hi friends
can any one please assit me running this piece of code in Mozilla firefox
It's running fine in IE. But it does not run in Firefox. Not even a error message.
Although IE Warns . Do you want to enable this script ?. And if i choose yes it runs fine.
Is there any tweak for this script so that it runs without any problem in Firefox..

```
<HTML>
<HEAD>
<script>
function this_total( for_what )
{
var this_row = for_what.parentElement.parentElement;
var qty = this_row.getElementsByTagName("td")[1].getElementsByTagName("input")[0].value;
var up = this_row.getElementsByTagName("td")[2].getElementsByTagName("input")[0].value;
var total = qty * up;
for_what.value = total;
return;
}
</script>
</HEAD>
<BODY>
<form name="form1">
<table border="1">
<tr>
<th> S.NO </th>
<th> Qty </th>
<th> Unit price </th>
<th> Total </th>
</tr>
<tr>
<td> <input type="text" name="sno"> </td>
<td> <input type="text" name="qty"> </td>
<td> <input type="text" name="up"> </td>
<td> <input type="text" name="total" onFocus="this_total( this )"> </td>
</tr>
<tr>
<td> <input type="text" name="sno"> </td>
<td> <input type="text" name="qty"> </td>
<td> <input type="text" name="up"> </td>
<td> <input type="text" name="total" onFocus="this_total( this )"> </td>
</tr>
<tr>
<td> <input type="text" name="sno"> </td>
<td> <input type="text" name="qty"> </td>
 <td> <input type="text" name="up"> </td>
 <td> <input type="text" name="total" onFocus="this_total( this )"> </td>
 </tr>
 </table>
 </form>
 </BODY>
```
Thanks


----------



## lexicon (Sep 10, 2006)

i'm using Mozilla Firefox v 3.6.3


----------



## MMJ (Oct 15, 2006)

Try parseInt


----------



## lexicon (Sep 10, 2006)

Hi MMJ
Sorry i didn't got you. could you please be more precise
i'm not a programmer.


----------



## MMJ (Oct 15, 2006)

var total = parseInt(qty, 10) * parseInt(up, 10);


----------



## lexicon (Sep 10, 2006)

Hi MMJ Thanks for the tip but it's still not working on Mozilla Firefox, IE is Okay.
revised code as suggested by MMJ

```
[TABLE]
[TR]
[TH] S.NO [/TH]
[TH] Qty [/TH]
[TH] Unit price [/TH]
[TH] Total [/TH]
[/TR]
[TR]
[TD]  [/TD]
[TD]  [/TD]
[TD]  [/TD]
[TD]  [/TD]
[/TR]
[TR]
[TD]  [/TD]
[TD]  [/TD]
[TD]  [/TD]
[TD]  [/TD]
[/TR]
[TR]
[TD]  [/TD]
[TD]  [/TD]
 [TD]  [/TD]
 [TD]  [/TD]
 [/TR]
 [/TABLE]

Thanks
```


----------



## lexicon (Sep 10, 2006)

Hi MMJ Thanks for the tip but it's still not working on Mozilla Firefox, IE is Okay.
revised code as suggested by MMJ

```
<HTML>
<HEAD>
<script>
function this_total( for_what )
{
var this_row = for_what.parentElement.parentElement;
var qty = this_row.getElementsByTagName("td")[1].getElementsByTagName("input")[0].value;
var up = this_row.getElementsByTagName("td")[2].getElementsByTagName("input")[0].value;
//var total = qty * up;
var total = parseInt(qty, 10) * parseInt(up, 10);
for_what.value = total;
return;
}
</script>
</HEAD>
<BODY>
<form name="form1">
<table border="1">
<tr>
<th> S.NO </th>
<th> Qty </th>
<th> Unit price </th>
<th> Total </th>
</tr>
<tr>
<td> <input type="text" name="sno"> </td>
<td> <input type="text" name="qty"> </td>
<td> <input type="text" name="up"> </td>
<td> <input type="text" name="total" onFocus="this_total( this )"> </td>
</tr>
<tr>
<td> <input type="text" name="sno"> </td>
<td> <input type="text" name="qty"> </td>
<td> <input type="text" name="up"> </td>
<td> <input type="text" name="total" onFocus="this_total( this )"> </td>
</tr>
<tr>
<td> <input type="text" name="sno"> </td>
<td> <input type="text" name="qty"> </td>
 <td> <input type="text" name="up"> </td>
 <td> <input type="text" name="total" onFocus="this_total( this )"> </td>
 </tr>
 </table>
 </form>
 </BODY>
</html>
```
Thanks


----------



## MMJ (Oct 15, 2006)

My bad, replace *parentElement* with *parentNode*. Should work in IE & FF.


----------



## lexicon (Sep 10, 2006)

Thanks MMJ it's working like charm.
Thanks once again.


----------

