javascript - onclick open window pass variable using document.getElementByID - Stack Overflow

What am I doing wrong? <input type='text' name='keyword' id='keyword'

What am I doing wrong?

<input type='text' name='keyword' id='keyword' size='16'>

<a href= "" onclick="window.open('.getElementById('keyword')');">

it opens a new window with without q = keyword.

What am I doing wrong?

<input type='text' name='keyword' id='keyword' size='16'>

<a href= "" onclick="window.open('http://scholar.google./scholar?q=document.getElementById('keyword')');">

it opens a new window with without q = keyword.

Share Improve this question edited Jul 10, 2012 at 19:56 LittleBobbyTables - Au Revoir 32.8k25 gold badges111 silver badges115 bronze badges asked Jul 10, 2012 at 19:55 campatskycampatsky 3241 gold badge3 silver badges14 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 3

You need to have document.getElementById('keyword') as part of the code, not the hyperlink.

<input type='text' name='keyword' id='keyword' size='16'>  

<a href= "" 
    onclick="window.open('http://scholar.google./scholar?q=' + document.getElementById('keyword') + '');"> 

You have the getElementById enclosed in quotes.

It should be:

<a href="" onclick="window.open('http://scholar.google./scholar?q=' + document.getElementById('keyword').value);">

Declaring document.getElementById('keyword')doesn't automatically give you the value written in it. For that, you need to do document.getElementById('keyword').value.

What you probably want to do is this:

<a onclick="window.open('http://scholar.google./scholar?q=' + document.getElementById('keyword').value);">Click here</a>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745110134a4611798.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信