Gowri
Gowri

Reputation: 16855

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 things are happening in Wordpress theme.

Working location

Modal form is existing here

Upvotes: 0

Views: 1839

Answers (3)

Robert Koritnik
Robert Koritnik

Reputation: 105081

getElementById should be provided with id not name attribute

Upvotes: 0

searlea
searlea

Reputation: 8388

(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").

Upvotes: 2

genesis
genesis

Reputation: 50982

You do not have

id="name" 

anywhere on page

Upvotes: 0

Related Questions