passing javascript params

I have a search box that I want javascript to open in a new window a google custom search enginne but pass the keyword from my site.

<form name="myform">
<input type="text" name="search_text" id="search_text"> <input type="button" name="search" onclick="goSearch()">
</form>

<script>
function goSearch() {
        var st = document.getElementById('search_text').value;
        window.open('https://www.google.com/cse/publicurl?cx=016143464297381313748:e13kxohrq8s' + st);
}
</script>

Firebug indicates the element ID is null. How do I capture the data for "search_text" with the onclick?
LVL 7
Robert SaylorSenior DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dave BaldwinFixer of ProblemsCommented:
Works fine here as long as you add a '&' to the query string before ' + st);
 window.open('https://www.google.com/cse/publicurl?cx=016143464297381313748:e13kxohrq8s&' + st);

Open in new window

0
Robert SaylorSenior DeveloperAuthor Commented:
I am having issues passing the element value with the on click. The window.open isn't the issue.

How do i pass the input type data using the on click?
0
Dave BaldwinFixer of ProblemsCommented:
I am not having any problem with your code.  If I type '123456' in the text input and click on the button, '123456' shows up at the end of the query string in the new window.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Robert SaylorSenior DeveloperAuthor Commented:
Thanks maybe something is preventing it i will look at my code more.
0
Dave BaldwinFixer of ProblemsCommented:
This is the exact code I was using.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>goSearch test</title>
</head>
<body>
<h1>goSearch test</h1>
<form name="myform">
<input type="text" name="search_text" id="search_text"> <input type="button" name="search" onclick="goSearch()">
</form>

<script>
function goSearch() {
        var st = document.getElementById('search_text').value;
        window.open('https://www.google.com/cse/publicurl?cx=016143464297381313748:e13kxohrq8s&' + st);
}
</script>

</body>
</html>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Brian TaoSenior Business Solutions ConsultantCommented:
Just a wild guess: is there any javascript code that disables the input?
0
Robert SaylorSenior DeveloperAuthor Commented:
I think there is another piece of javascript that is preventing it from working. However, I did find another way.

<form id="formSearch" name="formSearch" style="display:inline" action="http://www.google.com/cse" target=_blank>
<input type="hidden" name="cx" value="016143464297381313748:e13kxohrq8s">
<input type="hidden" name="ie" value="UFT-8">
<input type="text" name="q" id="search_txt">
<input type="submit">
</form>

Untimely my goal was to collect the search string and pass it to google in a new window. This did the trick.
0
Robert SaylorSenior DeveloperAuthor Commented:
BTW, you have to apply for a "cx" string that will search a domain you setup in google custom search.
0
Robert SaylorSenior DeveloperAuthor Commented:
I ended up using the solution I found from google. The code in my solution posted is from a google search.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.