Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New Coder
    Join Date
    Apr 2007
    Posts
    60
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Two search box and return key conflict

    In short with IExplorer go to page:

    http://www.aymavisi.org/hikaye/Dostu...%20Cibran.html

    and type something in search box Sitede Ara and hit enter key, you'll see two windows open. How to fix it?



    Google site search code:

    Code:
    <form id="searchbox_007319955694884483973:pnnwgtpio7g0" action="http://www.google.com/search" style="line-height: 100%; font-size:10pt; font-family:Times New Roman; background-color:#444577
    ; text-align:center" target="_blank">
    			<font size="3" face="Tahoma">
    			<input type="hidden" name="cof0" value="FORID:0" />
    			<input type="hidden" name="cx0" value="007319955694884483973:pnnwgtpio7g" />
    
    			</font>
    
    			<div style="padding-top: 2px">
    
    			<font size="3">
    
    			<input name="q" size="16" value=" " style="font-family:Tahoma; text-align:center; vertical-align:middle" /></font><span style="font-size: 7pt"><font size="3"><input type="submit" name="sa" value="Sitede Ara" style="font-family:Tahoma; width:75; height:18; vertical-align:middle" /></font></span></div>
    			</p>
    			<font size="3" face="Tahoma">
    			<input type="hidden" name="cx" value="007319955694884483973:pnnwgtpio7g" />
    			<input type="hidden" name="cof" value="FORID:0" />
    			</font>
    		</form>


    ----------------------------------------------------------------


    Wikipedia script code:

    Code:
    <script language="JavaScript" type="text/javascript">
    document.onkeydown = function(ev) {	
        var key;
        ev = ev || event;
        key = ev.keyCode;
    if (key == 13) {
    search_google();
    }
    }
    function search_google(){ 
    window.open("http://tr.wikipedia.org/wiki/"+document.search.query.value); 
    }
    </script>
    <form name="search" style="text-align: center; background-color:#444577">
    <div style="padding-top: 2px">
    <input type="text" name="query" value="" style="font-family: Tahoma; font-size: 10pt; vertical-align:middle; text-align:center" size="16"><input type="button" value="Sözlük" onClick="search_google()" style="font-family: Tahoma; font-size: 10pt; vertical-align:middle; height:18">
    </div>
    </form>

  • #2
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,876
    Thanks
    56
    Thanked 536 Times in 533 Posts
    you should validate your html

    lots of minor stuff, but I suspect the major problem here is not closing your form tags

  • #3
    New Coder
    Join Date
    Apr 2007
    Posts
    60
    Thanks
    3
    Thanked 0 Times in 0 Posts
    How to close form tags. I thought they're okay. But the problem is wikipedia script has listens enter key but using enter key on Sitede Ara box also triggers it.

  • #4
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,876
    Thanks
    56
    Thanked 536 Times in 533 Posts
    opening a form tag:
    Code:
    <form>
    closing a form tag:
    Code:
    </form>
    my theory (and I could well be wrong) is that being that your form tags are not closed, you are submitting both forms every time you hit the button, which leads to the behavior that you describe

  • #5
    New Coder
    Join Date
    Apr 2007
    Posts
    60
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Both my codes I can see both the tags, do I place them in wrong place? If I remove the part below then there's no conflict but this time search box of wikipedia doesn't accept return key.


    Code:
    document.onkeydown = function(ev) {	
        var key;
        ev = ev || event;
        key = ev.keyCode;
    if (key == 13) {
    search_google();
    }
    }

  • #6
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,876
    Thanks
    56
    Thanked 536 Times in 533 Posts
    oh, I get it now. Seems to me that best is to check which input has focus at the time of the enter key getting pressed:

    Code:
    document.onkeydown = function(ev) {
    if(ev.target.name=="query"){	
        var key;
        ev = ev || event;
        key = ev.keyCode;
    if (key == 13) {
    search_google();
    		}
    	}
    }

  • #7
    New Coder
    Join Date
    Apr 2007
    Posts
    60
    Thanks
    3
    Thanked 0 Times in 0 Posts
    I implied your code but now return key doesn't work for wikipedia search box.

  • #8
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,876
    Thanks
    56
    Thanked 536 Times in 533 Posts
    forgot about the IE thing, sorry:

    Code:
    document.onkeydown = function(ev) {
     ev = ev || event;
    if(ev.target.name=="query"){	
        var key;
        key = ev.keyCode;
    if (key == 13) {
    search_google();
    		}
    	}
    }
    Last edited by xelawho; 12-25-2012 at 08:03 PM.

  • #9
    New Coder
    Join Date
    Apr 2007
    Posts
    60
    Thanks
    3
    Thanked 0 Times in 0 Posts
    I put the new code on a new page same issue with IE 8

  • #10
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,876
    Thanks
    56
    Thanked 536 Times in 533 Posts
    wow. what a cross-browser nightmare here's one solution, although there may be better ones...

    Code:
    document.onkeydown = function(ev) {
    if (window.event) {
    var keycode = window.event.keyCode;
    var tg=window.event.srcElement;
    }
    else if (ev) {
    var keycode = ev.which;
    var tg=ev.target
    }
    if(tg.name=="query"&&keycode == 13){	
    search_google();
    	}
    }

  • Users who have thanked xelawho for this post:

    tunayx (12-25-2012)

  • #11
    New Coder
    Join Date
    Apr 2007
    Posts
    60
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Okay works perfect. Thanks thousands for your help and patience.
    Last edited by tunayx; 12-25-2012 at 09:14 PM.


  •  

    Posting Permissions

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