开发者

document.getElementById not working inside function

I am getting a strange problem while using document.getElementById inside a function. I have a form in modal window (Highslide). While the form is submitting, I am just calling function foo.Inside foo I am just selecting form elements by ID using document.getElementById. But doesn't present value, just returns default value. I tried jQuery html but it doesn't work.

My code

function foo(){
    var name = document.getElementById('yname').value; 
    // it just returns default value(null).
} 

<form onsubmit="return foo();">.......</form>

These thi开发者_开发百科ngs are happening in Wordpress theme.

Working location

Modal form is existing here


(Looking at the live code) Is that an attempt to grab the form field with an id of yname? Have you tried using yname instead of name? (your HTML contains input name="name" id="yname").


You do not have

id="name" 

anywhere on page


getElementById should be provided with id not name attribute

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜