Forty-Tip-Two…
When I started JavaGoodies, oh so long ago, I was sent a lot of scripts that were posted straightaway. I needed to fill space at first. As the months went on, I became more selective in what should be posted. I guess the two biggest criteria in posting a script were: is it original and is it functional? I received a bunch of scripts that would change the background of a page using everything from Event Handlers to a person’s name to make the change. Clever… but not overly useful. Once you have the basic concept of changing the background color, you pretty much can take it from there. This script was sent to me by a gentleman named Mujib. It’s a multiple search engine script. The script was much larger than you see it here. I’ve cut it down a bit for this series of Script Tips. It used to search ten different engines, now it’ll only do five. Of course, by the end you know it well enough to add as many searches as you’d like. The script is quite functional in that it allows many searches from one page. Results are posted in a new window so you never leave the search page. Plus, you don’t have to perform each search individually. You could put in a keyword (or keywords, cleverly enough) and all five search engines will return their results in five separate windows. It’s a very helpful, and involved, script. People have been asking that I get into some more advanced JavaScript. Well, this should fit the bill. First off, try it out and then grab the code.
The form code looks like this:
|
NAMEs
The name of the FORM itself is “searching.” The text box name is “query.” Each of the Checkboxes are given the name of the search engine they represent.
Finally, the button will trigger a function called
search().
Now we know enough to start constructing hierarchy statements, but unlike other forms we’ve dealt with here, this has multiple hierarchy statements depending on what the user chose. We’ll get into how the JavaScript knows which has been clicked later.
The Checkboxes
Yes, this could have also been done with radio buttons (See article
Link
) and, with some special coding, a drop-down menu. The reason the author chose checkboxes is that it allowed the user to check as many as desired. It didn’t limit the choice. Let’s look at the first checkbox code:
|
Same with the other four checkboxes. The VALUEs are equal to the URL required to perform a search on that particular engine. The code is pretty easy to find. You just go to the search page of the engine and look at the source code. I’m sure that’s where the author got it.
So we have a text box that assigns the variable “query” to keywords. We also have checkboxes that return URLs of search engines. Put the two together and you get a full search string. Seeing the process yet?
Next Time: What If There’s A Space?