search box results in a new window

Discussion in 'Javascript' started by Someone, Dec 23, 2005.

  1. Someone

    Someone Guest

    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>
     
    Someone, Dec 23, 2005
    #1
    1. Advertising

  2. Someone

    bobzimuta Guest

    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!
     
    bobzimuta, Dec 23, 2005
    #2
    1. Advertising

  3. Someone

    McKirahan Guest

    "Someone" <> wrote in message
    news:1c4hu1ivfedxu$...
    > 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>
     
    McKirahan, Dec 23, 2005
    #3
  4. Someone

    McKirahan Guest

    "McKirahan" <> wrote in message
    news:...
    > "Someone" <> wrote in message
    > news:1c4hu1ivfedxu$...
    > > 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>
     
    McKirahan, Dec 23, 2005
    #4
  5. Someone

    Someone Guest

    On Fri, 23 Dec 2005 16:38:20 -0600, McKirahan wrote:

    > "McKirahan" <> wrote in message
    > news:...
    >> "Someone" <> wrote in message
    >> news:1c4hu1ivfedxu$...
    >>> 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.

    <select name="db" class="style2">
    > <option value="*">Dictionary.com</option>


    What's with the value of '*'?
     
    Someone, Dec 23, 2005
    #5
  6. Someone

    Someone Guest

    On 23 Dec 2005 14:07:14 -0800, bobzimuta wrote:

    > 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.
     
    Someone, Dec 24, 2005
    #6
  7. Someone

    McKirahan Guest

    "Someone" <> wrote in message
    news:1iu4sgggj3biw.fqvxvvuef3yl$...
    > On Fri, 23 Dec 2005 16:38:20 -0600, McKirahan wrote:
    >
    > > "McKirahan" <> wrote in message
    > > news:...
    > >> "Someone" <> wrote in message
    > >> news:1c4hu1ivfedxu$...
    > >>> 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]

    > 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.
    >
    > <select name="db" class="style2">
    > > <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.
     
    McKirahan, Dec 24, 2005
    #7
  8. Someone

    RobG Guest

    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.


    [...]


    --
    Rob
     
    RobG, Dec 24, 2005
    #8
  9. Someone

    McKirahan Guest

    "RobG" <> wrote in message
    news:43ace12a$0$14676$...

    [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.
     
    McKirahan, Dec 24, 2005
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?ZGhucml2ZXJzaWRl?=

    Using AJAX for a search results box

    =?Utf-8?B?ZGhucml2ZXJzaWRl?=, Aug 24, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    705
    Bruce Barker
    Aug 24, 2005
  2. borgus
    Replies:
    3
    Views:
    597
  3. Gnarlodious
    Replies:
    4
    Views:
    17,679
    elizas
    May 5, 2010
  4. Replies:
    1
    Views:
    1,216
    Andrew Thompson
    Feb 6, 2007
  5. Craig Keightley
    Replies:
    10
    Views:
    279
    Craig Keightley
    Jun 29, 2005
Loading...

Share This Page