Avatar of Robert Saylor
Robert Saylor
Flag 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?
JavaScript

Avatar of undefined
Last Comment
Robert Saylor

8/22/2022 - Mon
Dave Baldwin

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

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?
Dave Baldwin

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.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Robert Saylor

ASKER
Thanks maybe something is preventing it i will look at my code more.
ASKER CERTIFIED SOLUTION
Dave Baldwin

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Brian Tao

Just a wild guess: is there any javascript code that disables the input?
SOLUTION
Robert Saylor

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Robert Saylor

ASKER
BTW, you have to apply for a "cx" string that will search a domain you setup in google custom search.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Robert Saylor

ASKER
I ended up using the solution I found from google. The code in my solution posted is from a google search.