0

Hi all, i seem to be having an issue with a calculate function i have made,. the script works fine in all browsers except Firefox! I was hoping someone could lend a hand and explain what I'm doing wrong.

The JS:

<code>
<script type="text/javascript">
//Calculator formulae
function multiply(){
Form.result.value = ((form.inputA.value * form.inputB.value * form.inputC.value * 150) / 1000000) ;
</code>

The form;

<code>
<form id="Form" action="">
<fieldset>
<input type="text" name="inputA" value="" />
<input type="text" name="inputB" value="" />
<input type="text" name="inputC" value="" />
<input type="button" name="calc" value="Calculate" onclick="multiply()"/>
<input type="text" name="result" value="" />
</fieldset>
</form>
</code>

7
Contributors
16
Replies
17
Views
5 Years
Discussion Span
Last Post by jpknoob
0

Thanks for your response, but this is only a snip of my code, the original code has all the correct jazz, just not working in FF.

Edit;

The JS:

<code>
<script type="text/javascript">
//Calculator formulae
function multiply(){
Form.result.value = ((form.inputA.value * form.inputB.value * form.inputC.value * 150) / 1000000) ;
}
</script>
</code>

The form;

<code>
<form id="Form" action="">
<fieldset>
<input type="text" name="inputA" value="" />
<input type="text" name="inputB" value="" />
<input type="text" name="inputC" value="" />
<input type="button" name="calc" value="Calculate" onclick="multiply()"/>
<input type="text" name="result" value="" />
</fieldset>
</form>
</code>

0

do you have
<code>

</code>

in your file, or are they supposed to suggest code tags on this forum?

does it give any result, does it give an javascript error, ... ?

Edited by stultuske: n/a

0

The code tags were supposed to be forum tags, another typo, d'oh!

The code runs perfectly in all browsers except FF, when i hit the calculate button, nothing happens.

Edited by jpknoob: n/a

0

I would suggest using the id attribute instead of the name attribute and using document.getElementById in your javascript.

0

try this:

<script type="text/javascript">
//Calculator formulae
function multiply(){
document.Form.result.value = ((form.inputA.value * form.inputB.value * form.inputC.value * 150) / 1000000) ;
}
</script>
0

actually... javascript is case sensitive so since you named your form 'Form'
you need to reference 'Form' not 'form'. anyway... try this.

<script type="text/javascript">
//Calculator formulae
function multiply(){
document.Form.result.value = ((document.Form.inputA.value * document.Form.inputB.value * document.Form.inputC.value * 150) / 1000000) ;
}
</script>
0

Have tried the "document.Form.result.value..." but had no luck. i will give the "document.getElementById" a go, can anyone recommend any good tutorials for this method? I'm new to java script

0

It's easier to pass a reference to the form element from the onclick handler.

This avoids having to discover the form in the DOM with document.all , document.getElementById() , document.forms[] etc.

function multiply(form){
	form.result.value = ((form.inputA.value * form.inputB.value * form.inputC.value * 150) / 1000000) ;
}
<form action="">
	<fieldset>
		<input type="text" name="inputA" value="" />
		<input type="text" name="inputB" value="" />
		<input type="text" name="inputC" value="" />
		<input type="button" name="calc" value="Calculate" onclick="multiply(this.fom)"/>
		<input type="text" name="result" value="" />
	</fieldset>
</form>

Airshow

0

In function multiply(), I changed your 'form' ID to capitalized 'Form'. That made your code work in Iceweasel (Firefox), Konqueror, Epiphany and Opera on Debian. Epiphany very usefully printed the error on stderr.

For tracing and debugging JS, download http://getfirebug.com/. It works well for me (I have a 10k line JS program written from scratch; Firebug makes it easy to debug the program in Iceweasel/Firefox.) It told me exactly what the problem was.

For all you'd want to know about JS, get David Flanagan's "Javascript the Definitive Guide" (O'Reilly, ISBN 0-596-10199-6). I'm still using the 5th edition (1996); it's what I used to learn JS.

0

Thank you very much for the feedback and advice, i will explore these and get back with an update, hopefully a solution!

0

Try your code with: <!doctype native> instead of whatever doctype you are using currently
and you're a go!

0

Hi Troy, <!doctype native> sounds fascinating. Do you have a reference for it please?

Airshow

0

Hello all and happy new year!

I tried Troy III recommendation and it worked! I have never heard of doctype native and am still bemused as to why this works. I was using strict doctype before. Thanks all for the help/advice

0

Just an update, changing the doctype resulted in non validation from w3, so i reverted back to an earlier comment to use the document.getElementById and managed to get it to work. For those interested, the javascript code looks like;

document.getElementById("result").value = ((document.getElementById("inputA").value * document.getElementById("inputB").value * document.getElementById("inputC").value * 150) / 1000000);

and in the HTML, i change the name to id.

Thanks all for the help

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.