开发者

Javascript: Can‘t get document.getelementbyid to work

I found many questions concerning form elements that are null but I s开发者_StackOverflow中文版imply 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".


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!


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" />


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜