Problems with Javascript code (Full Version)

All Forums >> [Web Development] >> ASP and Database



Message


JohnH -> Problems with Javascript code (2/1/2008 8:16:51)

Hi,

I found the folling code on the Internet that I use to take VAT (UK tax) from a total amount. By the way, this script is placed in between the HEAD tags.

<SCRIPT LANGUAGE="JavaScript">

<!-- Begin
function doMath() {
var one = eval(document.FrontPage_Form1.total.value)
var two = eval(document.FrontPage_Form1.vat.value)
var prod = one / two
document.FrontPage_Form1.PURCHASE_VALUE.value=custRound(prod,2);
}

function custRound(x,places) {
return (Math.round(x*Math.pow(10,places)))/Math.pow(10,places)
}

// End -->
</SCRIPT>

The problem I have is that the javascript only seems to work if FrontPage_Form1 is the first form in the page. That is not the case in my HTML.

Can anyone help?

Many thanks,

John




Tailslide -> RE: Problems with Javascript code (2/1/2008 8:19:06)

can you show us the HTML too please.




JohnH -> RE: Problems with Javascript code (2/1/2008 8:22:37)

I have just fixed it!

I replaced

document.FrontPage_Form1

with

document.forms[2]

[2] being the 3rd form in my page. It uses 0 as the first.

Thanks,

John




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.046875