Bengau
Bengau

Reputation: 175

How to define an input id in javascript?

Hi i am not good in javascript. This is a part of code from my ajax search auto-suggest and i need to replace "word" text with the text that comes from input. How can I do that?

<input type="text" id="selectedInput"/><ul id="list"></ul>    
<script>    
var keyword = "word";  (wrong code)      
url: "http://itunes.apple.com/search?term=" + keyword + "&entity=musicTrack",
..

See http://jsfiddle.net/coladeu/Qhj5N/3/

Upvotes: 2

Views: 6038

Answers (2)

Matthew Cox
Matthew Cox

Reputation: 13682

This will obtain the value in your textbox.

var keyword = document.getElementById('selectedInput').value;

Edit:

Just as an FYI, the same thing can be accomplished using jQuery:

$('#selectedInput').val();

Upvotes: 3

nandu
nandu

Reputation: 779

You can use $('#selectedInput').val() here is an example

http://jsfiddle.net/Qhj5N/4/

Upvotes: 1

Related Questions