0

I found many questions concerning form elements that are null but I simply can‘t get this to work.

It works in every browser but when it‘s embedded in Wordpress it stops working in Firefox. The Firefox-Console says I should use document.getelementbyid but in every way I try it, Firefox says the form is null or that "myform is not defined".

3
  • It'll be easier to debug if you show is the version that ISN'T working, as opposed to the one that is. Commented Mar 1, 2011 at 19:36
  • @hunter: the link to dropbox has his code. @Philipp: Please explain what the problem is. Is it just the message? "It stops working" is not very helpful, specially when you didn't specify what working means... Commented Mar 1, 2011 at 19:40
  • I just fixed with Spidys help. Thanks a lot anyways! You guys are fast! Commented Mar 1, 2011 at 19:46

3 Answers 3

2

Your script uses myform as a global variable. Don't do that, that was an early hack from Internet Explorer, that created global variables for all elements with id/names and is currently frowned upon.

That's what the error message on Firefox tells you.

"Element referenced by ID/NAME in the global scope. Use W3C standard document.getElementById() instead. var userInputs = myform.elements; (rechner.html.22)

Add the following to the top of your calculate function

var myForm = document.getElementById('myform') 

And change your form tag to be:

 <form name="myform" id="myform" action="#"> 

If this is not the issue at hand, please make your question more descriptive!

Sign up to request clarification or add additional context in comments.

1 Comment

That was the issue. Thank you as well. This page is more than awesome, a seamless and great way to get help. I‘ll try to give something back now…
1

Can you post the html and javascript code? my first guess is that you didn't give the form or input an id attribute. For example

<input name="myInput" type="text" />

will not work for

document.getElementById("myInput").

You need to add the id attribute like so

<input id="myInput" name="myInput" type="text" /> 

2 Comments

Wow! That was the proplem. I simply put the name tag and not the id tag, by adding the id tag, everything works fine now! Thanks a lot for this fast reply, I should‘ve asked earlier. Thanks!
I had the same issue on firefox with a login script I wrote. Such a bugger to find when it works on Chrome and IE
0

Try using different ID, maybe total already exists in wordpress theme. Can you please show this embeded in wordpress? It would be quite easier to debug.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.