Robert Saylor
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('s earch_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?
<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('s
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?
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?
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.
ASKER
Thanks maybe something is preventing it i will look at my code more.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Just a wild guess: is there any javascript code that disables the input?
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
BTW, you have to apply for a "cx" string that will search a domain you setup in google custom search.
ASKER
I ended up using the solution I found from google. The code in my solution posted is from a google search.
Open in new window