最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

How to define an input id in javascript? - Stack Overflow

matteradmin5PV0评论

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 es from input. How can I do that?

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

See /

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 es 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./search?term=" + keyword + "&entity=musicTrack",
..

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

Share Improve this question edited Sep 23, 2012 at 18:54 Adi 5,1796 gold badges35 silver badges48 bronze badges asked Sep 23, 2012 at 18:50 BengauBengau 1755 silver badges14 bronze badges 2
  • When do you want it? When the page loads? Or when an event occurs? – I Hate Lazy Commented Sep 23, 2012 at 18:56
  • i want it when event occurs. when i type characters, to start show me the suggestions. i dont think is that hard but i am not good in js. – Bengau Commented Sep 23, 2012 at 20:11
Add a ment  | 

2 Answers 2

Reset to default 3

This will obtain the value in your textbox.

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

Edit:

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

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

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

http://jsfiddle/Qhj5N/4/

Post a comment

comment list (0)

  1. No comments so far