最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin1浏览0评论

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/

发布评论

评论列表(0)

  1. 暂无评论