0

What am I doing wrong?

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

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

it opens a new window with without q = keyword.

3 Answers 3

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.com/scholar?q=' + document.getElementById('keyword') + '');"> 
Sign up to request clarification or add additional context in comments.

Comments

2

You have the getElementById enclosed in quotes.

It should be:

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

Comments

0

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.com/scholar?q=' + document.getElementById('keyword').value);">Click here</a>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.