user3123222
user3123222

Reputation: 1215

How can I get the value of an HTML variable and store it inside a javascript variable?

I have this line of code here. This is pretty much a textfield in HTML that gets the value typed in and stores it in the id called "inpKeyword."

<input type="text" name="keyword" value="Keyword" size="25" id="inpKeyword"/> <!-- enter search term -->

I need to have that value stored in a javascript var variable. Can someone please help me? I've been stuck on this problem for the past couple hours. Thanks in advanced!

Btw, this is all in a JSP page.

Upvotes: 0

Views: 87

Answers (2)

blackpanther
blackpanther

Reputation: 11486

Alternatively, you could use jQuery:

var value = $('#inpKeyword').val();

Upvotes: 0

T McKeown
T McKeown

Reputation: 12847

Have you tried this?

var val = document.getElementById('inpKeyword').value;

Upvotes: 6

Related Questions