search box results in a new window

S

Someone

Hi,

I wish to use a dictionary.com search box and want the results of a search
to open in a new window. Is there a way to do this using their code? The
copy and paste code is provided below. Thanks for any help?

<form method="get" action="http://dictionary.reference.com/search">
<table border="0" cellspacing="4" cellpadding="4" bgcolor="#0033ff">
<tr>
<td valign="middle" align="left">
&nbsp;<strong style="font-family: arial,helvetica,sans-serif; font-size:
115%; color: #ffffff;">Search:</strong>&nbsp;
<select name="db" style="font-size:11pt; font-family:
arial,helvetica,sans-serif;">
<option value="*">Dictionary.com</option>
<option value="roget">Thesaurus.com</option>
<option value="wiki">Reference.com</option>
<option value="web">the Web</option>
</select>
&nbsp;<strong style="font-family: arial,helvetica,sans-serif; font-size:
115%; color: #ffffff;">for</strong>
&nbsp;<input type="text" name="q" size="20" maxlength="50"
style="font-size:11pt;">
&nbsp;<input type="submit" value="Go" style="font-weight:bold;
font-size:11pt; font-family: arial,helvetica,sans-serif;">
</td>
</tr>
</table>
</form>
 
B

bobzimuta

Is this with their permission? Or just a project for your personal
interest? Be careful of hitting someone elses' server without direct
consent. If you use their bandwidth (granted you'll be using an
insignificant amount) they may and will get pissed.

I wrote a script (server side) that parsed a site's racecar standings
into xml. I asked, never got a response so I went ahead anyway. Every
week or two during race season, the web developer rewrote the html file
so I had to rewrite the parser. Bastards!
 
M

McKirahan

Someone said:
Hi,

I wish to use a dictionary.com search box and want the results of a search
to open in a new window. Is there a way to do this using their code? The
copy and paste code is provided below. Thanks for any help?

[snip]

Will this help? Watch for word-wrap.

<html>
<head>
<title>Dictionary.htm</title>
<script type="text/javascript">
var ref = new Array();
ref[0] = "http://dictionary.reference.com/search?q="
ref[1] = "http://thesaurus.reference.com/search?q=";
ref[2] = "http://www.reference.com/search?db=wiki&q=";
ref[3] = "http://www.reference.com/search?db=web&q=";
function formcheck() {
for (var i=0; i<4; i++) {
if (document.search_form.db.checked) {
var url = ref + escape(document.search_form.q.value);
window.open(url,"Dictionary","");
}
}
}
</script>
</head>
<body onload="document.search_form.q.focus()">
<form name="search_form" method="get"
action="http://dictionary.reference.com/search" onsubmit="return
formcheck();">
<input type="text" name="q" value="" size="35" maxlength="256">
<input type="submit" value="Search"><br>
<input type="radio" name="db" value="*" id="d" checked>Dictionary
<input type="radio" name="db" value="roget" id="t">Thesaurus
<input type="radio" name="db" value="wiki" id="e">Encyclopedia
<input type="radio" name="db" value="web" id="w">Web
</form>
</body>
</html>
 
M

McKirahan

McKirahan said:
Someone said:
Hi,

I wish to use a dictionary.com search box and want the results of a search
to open in a new window. Is there a way to do this using their code? The
copy and paste code is provided below. Thanks for any help?

[snip]

Here it is with your interface but with CSS:

<html>
<head>
<title>Dictionary.html</title>
<script type="text/javascript">
var page = new Array();
page[0] = "http://dictionary.reference.com/search?q="
page[1] = "http://thesaurus.reference.com/search?q=";
page[2] = "http://www.reference.com/search?db=wiki&q=";
page[3] = "http://www.reference.com/search?db=web&q=";
function formcheck() {
var form = document.search_form;
var valu = form.q.value;
var pick = form.db.selectedIndex;
window.open(page[pick] + escape(valu),"Dictionary","");
}
</script>
<style type="text/css">
..style1 { font-family: arial,helvetica,sans-serif; font-size:115%;
font-weight: bold; color: #ffffff; padding: 10px; }
..style2 { font-size:11pt; font-family:arial,helvetica,sans-serif; }
..style3 {font-weight:bold; font-size:11pt; font-family:
arial,helvetica,sans-serif; }
</style>
</head>
<body onload="document.search_form.q.focus()">
<form method="get" name="search_form">
<table border="0" cellspacing="4" cellpadding="4" bgcolor="#0033ff">
<tr>
<td>
<span class="style1">Search:</span>
<select name="db" class="style2">
<option value="*">Dictionary.com</option>
<option value="roget">Thesaurus.com</option>
<option value="wiki">Reference.com</option>
<option value="web">the Web</option>
</select>
<span class="style1">for</span>
<input type="text" name="q" size="20" maxlength="50"
style="font-size:11pt;">
<input type="button" value="Go" class="style3" onclick="formcheck()">
</td>
</tr>
</table>
</form>
</body>
</html>
 
S

Someone

McKirahan said:
Someone said:
Hi,

I wish to use a dictionary.com search box and want the results of a search
to open in a new window. Is there a way to do this using their code? The
copy and paste code is provided below. Thanks for any help?

[snip]

Here it is with your interface but with CSS:

<html>
<head>
<title>Dictionary.html</title>
<script type="text/javascript">
var page = new Array();
page[0] = "http://dictionary.reference.com/search?q="
page[1] = "http://thesaurus.reference.com/search?q=";
page[2] = "http://www.reference.com/search?db=wiki&q=";
page[3] = "http://www.reference.com/search?db=web&q=";
function formcheck() {
var form = document.search_form;
var valu = form.q.value;
var pick = form.db.selectedIndex;
window.open(page[pick] + escape(valu),"Dictionary","");
}
</script>
<style type="text/css">
.style1 { font-family: arial,helvetica,sans-serif; font-size:115%;
font-weight: bold; color: #ffffff; padding: 10px; }
.style2 { font-size:11pt; font-family:arial,helvetica,sans-serif; }
.style3 {font-weight:bold; font-size:11pt; font-family:
arial,helvetica,sans-serif; }
</style>
</head>
<body onload="document.search_form.q.focus()">
<form method="get" name="search_form">
<table border="0" cellspacing="4" cellpadding="4" bgcolor="#0033ff">
<tr>
<td>
<span class="style1">Search:</span>
<select name="db" class="style2">
<option value="*">Dictionary.com</option>
<option value="roget">Thesaurus.com</option>
<option value="wiki">Reference.com</option>
<option value="web">the Web</option>
</select>
<span class="style1">for</span>
<input type="text" name="q" size="20" maxlength="50"
style="font-size:11pt;">
<input type="button" value="Go" class="style3" onclick="formcheck()">
</td>
</tr>
</table>
</form>
</body>
</html>

Thanks for this, amazing! I have customised the code as below because
hitting enter did not work to get the results, but thanks again.

<input type="text" name="q" size="20" maxlength="50"
style="font-size:11pt;" onKeyDown="if(event.keyCode == 13) formcheck()">

Also can someone please explain what this is doing exactly, just so I am
aware.

<option value="*">Dictionary.com</option>

What's with the value of '*'?
 
S

Someone

Is this with their permission? Or just a project for your personal
interest? Be careful of hitting someone elses' server without direct
consent. If you use their bandwidth (granted you'll be using an
insignificant amount) they may and will get pissed.

I wrote a script (server side) that parsed a site's racecar standings
into xml. I asked, never got a response so I went ahead anyway. Every
week or two during race season, the web developer rewrote the html file
so I had to rewrite the parser. Bastards!

The website advertises a free search engine for use on other websites and
provides code to integrate into your web page. There is nothing saying the
code cannot be customised that I am aware of either. Linking to other sites
should never be a problem surely.
 
M

McKirahan

Someone said:
[snip]

Thanks for this, amazing! I have customised the code as below because
hitting enter did not work to get the results, but thanks again.

<input type="text" name="q" size="20" maxlength="50"
style="font-size:11pt;" onKeyDown="if(event.keyCode == 13) formcheck()">

Also can someone please explain what this is doing exactly, just so I am
aware.

<option value="*">Dictionary.com</option>

What's with the value of '*'?

Rather than worry about key events; try this instead:

<html>
<head>
<title>Dictionary.html</title>
<script type="text/javascript">
var page = new Array();
page[0] = "http://dictionary.reference.com/search?q="
page[1] = "http://thesaurus.reference.com/search?q=";
page[2] = "http://www.reference.com/search?db=wiki&q=";
page[3] = "http://www.reference.com/search?db=web&q=";
function formcheck() {
var form = document.search_form;
var valu = form.q.value;
if (valu.length == 0) return false;
var pick = form.db.selectedIndex;
window.open(page[pick] + escape(valu),"Dictionary","");
return false;
}
</script>
<style type="text/css">
..style1 { font-family: arial,helvetica,sans-serif; font-size:115%;
font-weight: bold; color: #ffffff; padding: 10px; }
..style2 { font-size:11pt; font-family:arial,helvetica,sans-serif; }
..style3 {font-weight:bold; font-size:11pt; font-family:
arial,helvetica,sans-serif; }
</style>
</head>
<body onload="document.search_form.q.focus()">
<form method="get" name="search_form" onsubmit="return formcheck()">
<table border="0" cellspacing="4" cellpadding="4" bgcolor="#0033ff">
<tr>
<td>
<span class="style1">Search:</span>
<select name="db" class="style2">
<option value="*">Dictionary.com</option>
<option value="roget">Thesaurus.com</option>
<option value="wiki">Reference.com</option>
<option value="web">the Web</option>
</select>
<span class="style1">for</span>
<input type="text" name="q" size="20" maxlength="50"
style="font-size:11pt;">
<input type="submit" value="Go" class="style3">
</td>
</tr>
</table>
</form>
</body>
</html>


The "*" just assures that there is a value for the default selection.
 
R

RobG

McKirahan wrote:
[...]
Rather than worry about key events; try this instead:

<html>
<head>
<title>Dictionary.html</title>
<script type="text/javascript">
var page = new Array();
page[0] = "http://dictionary.reference.com/search?q="
page[1] = "http://thesaurus.reference.com/search?q=";
page[2] = "http://www.reference.com/search?db=wiki&q=";
page[3] = "http://www.reference.com/search?db=web&q=";
function formcheck() {
var form = document.search_form;
var valu = form.q.value;
if (valu.length == 0) return false;
var pick = form.db.selectedIndex;
window.open(page[pick] + escape(valu),"Dictionary","");
return false;
}
</script>
<style type="text/css">
.style1 { font-family: arial,helvetica,sans-serif; font-size:115%;
font-weight: bold; color: #ffffff; padding: 10px; }
.style2 { font-size:11pt; font-family:arial,helvetica,sans-serif; }
.style3 {font-weight:bold; font-size:11pt; font-family:
arial,helvetica,sans-serif; }
</style>
</head>
<body onload="document.search_form.q.focus()">
<form method="get" name="search_form" onsubmit="return formcheck()">
<table border="0" cellspacing="4" cellpadding="4" bgcolor="#0033ff">
<tr>
<td>
<span class="style1">Search:</span>
<select name="db" class="style2">
<option value="*">Dictionary.com</option>
<option value="roget">Thesaurus.com</option>
<option value="wiki">Reference.com</option>
<option value="web">the Web</option>

I don't understand why you use values for the options then ignore them
when accessing the array. It makes the order of the values in the
array dependent on the order of the options.

Why not use the option value as the key to an object? e.g.

var page = {
dictionary : "http://dictionary.reference.com/search?q=",
roget : "http://thesaurus.reference.com/search?q=",
wiki : "http://www.reference.com/search?db=wiki&q=",
web : "http://www.reference.com/search?db=web&q="
}


Then the function changes to:

var pick = form.db.options[form.db.selectedIndex].value;

And the order of items in the page object is independent of the order
of the options in the select.


[...]
 
M

McKirahan

[snip]
I don't understand why you use values for the options then ignore them
when accessing the array. It makes the order of the values in the
array dependent on the order of the options.

Why not use the option value as the key to an object? e.g.

var page = {
dictionary : "http://dictionary.reference.com/search?q=",
roget : "http://thesaurus.reference.com/search?q=",
wiki : "http://www.reference.com/search?db=wiki&q=",
web : "http://www.reference.com/search?db=web&q="
}


Then the function changes to:

var pick = form.db.options[form.db.selectedIndex].value;

And the order of items in the page object is independent of the order
of the options in the select.

Good point.

I originally posted one approach (and later merged it with the OP's)
whose form was strictly based on dictionary.com's.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top