Link to home
Create AccountLog in
Avatar of Robert Saylor
Robert SaylorFlag for United States of America

asked on

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?
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

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

Avatar of Robert Saylor

ASKER

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?
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.
Thanks maybe something is preventing it i will look at my code more.
ASKER CERTIFIED SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Just a wild guess: is there any javascript code that disables the input?
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
BTW, you have to apply for a "cx" string that will search a domain you setup in google custom search.
I ended up using the solution I found from google. The code in my solution posted is from a google search.