Your Ad Here Your Ad Here
Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Help With Javascript.

  1. #1
    This for all you script-guru's:

    Yesterday I was trying to make a simple Jscript for my brother's homepage that allows to use different searchengines to search the web, but I was surprise when the script didn't work with Explorer, while it did with Opera 7.2.

    Now here is what I wrote:

    <HEAD>
    &#60;script type="text/javascript" >
    function goToSearch()
    {
    &nbsp; &nbsp; if (window.event.keyCode == 13)
    &nbsp; &nbsp; {&nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Search()
    &nbsp; &nbsp; &nbsp; }

    }
    function Search()
    {
    &nbsp; &nbsp; term = window.document.searchform.querry.value ;
    &nbsp; &nbsp; location.href ="http://www.google.nl/search?q=" + term

    }
    </script >
    </head>
    <body>
    <FORM name="searchform">
    <input type=&#39;text&#39; size=&#39;20&#39; name=&#39;querry&#39;&nbsp; onKeyPress="goToSearch()">
    <input type=&#39;button&#39; size=&#39;10&#39; value=&#39;Go&#39; onclick="Search()">
    </FORM>
    bla blas
    bla bla
    .
    .
    .
    .
    </body>
    did I do somthing wrong? Oh yeah I forgot the script works fine in Explorer & Opera in case I use the button instead of the Enter-key, but that just annoying. I mean everyone is use the type somethng in the the textfield and than hit the enter-key .
    So the real problem is how to get this script to work with a the Enter-key?.
    I tried onSumbit="", but that didn&#39;t work(It was a dumb move I know ). I also tried to copy the body of the second function to the first one, but that also didn&#39;t help.
    One thing that did work for all browers was the open commad, if I use window.open() instead of loction.href="", I get no problems at all except that my brother doesn&#39;t want that.
    So any help would be aprceiated guys.



    PS: I apologize if this the wrong place to post such a problem.

  2. Software & Hardware   -   #2
    Out of The Ordinary
    Join Date
    Feb 2003
    Posts
    4,113
    Try this:

    Code:
    &#60;script type=&#34;text/javascript&#34; &#62;
    function goToSearch&#40;&#41;
    {
     * *if &#40;window.event.keyCode == 13&#41;
     * *{ *
     * * * * * *Search&#40;&#41;
     * * *}
    
    }
    function Search&#40;&#41;
    {
     * *term = window.document.searchform.querry.value;
     * *location.href =&#34;http&#58;//www.google.nl/search?q=&#34; + term
    
    }
    &#60;/script&#62;
    &#60;body&#62;
    &#60;FORM name=&#34;searchform&#34;&#62;
    &#60;input type=&#39;text&#39; size=&#39;20&#39; name=&#39;querry&#39; *onKeyPress=&#34;goToSearch&#40;&#41;&#34;&#62;
    &#60;input type=&#39;button&#39; size=&#39;10&#39; value=&#39;Go&#39; onclick=&#34;Search&#40;&#41;&#34;&#62;
    &#60;/FORM&#62;
    bla blas
    bla bla
    .
    .
    .
    .
    &#60;/body&#62;
    &#60;/script&#62;
    &#60;/html&#62;
    BOT

  3. Software & Hardware   -   #3
    Hi Bot&#33;

    You trick didn&#39;t work&#33;
    May i ask why did you add this tag </script> after the body tag? were you trying to put the form inside the script?

    Anyway thanx for yoor help.

  4. Software & Hardware   -   #4
    Out of The Ordinary
    Join Date
    Feb 2003
    Posts
    4,113
    Sorry My fault, this code work:

    Code:
    &#60;HTML&#62;
    &#60;HEAD&#62;
    
    &#60;/HEAD&#62;
    
    &#60;script type=&#34;text/javascript&#34; &#62;
    function goToSearch&#40;&#41;
    {
     &nbsp; &nbsp;if &#40;window.event.keyCode == 13&#41;
     &nbsp; &nbsp;{ &nbsp;
     &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Search&#40;&#41;
     &nbsp; &nbsp; &nbsp;}
    
    }
    function Search&#40;&#41;
    {
     &nbsp; &nbsp;term = window.document.searchform.querry.value&#59;
     &nbsp; &nbsp;location.href =&#34;http&#58;//www.google.nl/search?q=&#34; + term
    
    }
    &#60;/script&#62;
    &#60;body&#62;
    &#60;FORM name=&#34;searchform&#34;&#62;
    &#60;input type=&#39;text&#39; size=&#39;20&#39; name=&#39;querry&#39; &nbsp;onKeyPress=&#34;goToSearch&#40;&#41;&#34;&#62;
    &#60;input type=&#39;button&#39; size=&#39;10&#39; value=&#39;Google&#39; onclick=&#34;Search&#40;&#41;&#34;&#62;
    &#60;/FORM&#62;
    bla
    bla
    &#60;/body&#62;
    &#60;/HTML&#62;
    BOT

  5. Software & Hardware   -   #5
    Forum Star
    Join Date
    Jun 2002
    Posts
    1,407
    Better code would be:

    Code:
    &#60;script type=&#34;text/javascript&#34;&#62;
    function search&#40;&#41;
    {
     * term = window.document.searchform.query.value;
     * location.href =&#34;http&#58;//www.google.nl/search?q=&#34; + term
    
    }
    &#60;/script&#62;
    &#60;body&#62;
    &#60;FORM name=&#34;searchform&#34; action=&#34;search&#40;&#41;;&#34;&#62;
    &#60;input type=&#34;text&#34; size=&#34;20&#34; name=&#34;query&#34;&#62;
    &#60;input type=&#34;button&#34; size=&#34;10&#34; value=&#34;Go&#34;&#62;
    &#60;/FORM&#62;&#60;/body&#62;
    &#60;/script&#62;
    &#60;/html&#62;

  6. Software & Hardware   -   #6
    Hi Bot&#33;

    The code you posted is the same as my code. So let explain the problem agian.

    What I wanna do is envoke the script by hitting the ENTER-key, not with clicking a button. is that possible? [ I&#39;m no scriptkiddy, I usually get my cripts from internet, or just copy them from other poeple&#39;s pages.]

    And Paul thanx for your reply, but I tried that code before and it works only with Opera [it&#39;s a shame that opera is not popular as IE].

  7. Software & Hardware   -   #7
    Forum Star
    Join Date
    Jun 2002
    Posts
    1,407
    This works 100%:

    Code:
    &#60;html&#62;&#60;body&#62;&#60;script type=&#34;text/javascript&#34;&#62;
    function search&#40;&#41;
    {
     *term = document.searchform.query.value;
     *location.href =&#34;http&#58;//www.google.nl/search?q=&#34; + term
    
    }
    &#60;/script&#62;
    &#60;body&#62;
    &#60;FORM name=&#34;searchform&#34; action=&#34;javascript&#58;search&#40;&#41;;&#34;&#62;
    &#60;input type=&#34;text&#34; size=&#34;20&#34; name=&#34;query&#34;&#62;
    &#60;input type=&#34;submit&#34; value=&#34;Go&#34;&#62;
    &#60;/FORM&#62;
    &#60;/body&#62;
    &#60;/html&#62;

  8. Software & Hardware   -   #8
    great piece of code, Paul
    <span style='font-size:14pt;line-height:100%'>BLAH</span>

    <span style='font-size:14pt;line-height:100%'>Wayne Rooney - A thug and a thief</span>

  9. Software & Hardware   -   #9
    Thanx a lot Pual&#33; You the MAN.
    I couldn&#39;t say it better than 3rd gen noob&#33;

    Nice avatar bij the way&#33;&#33;&#33;&#33;&#33;&#33;&#33; Where did you get it? hahahah

  10. Software & Hardware   -   #10
    Wooh, Nice.



Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •