Reputation: 3
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".
Upvotes: 0
Views: 2554
Reputation: 92324
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!
Upvotes: 2
Reputation: 40002
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" />
Upvotes: 1
Reputation: 1
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.
Upvotes: 0