Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-25-2012, 04:11 PM   PM User | #1
tunayx
New Coder

 
Join Date: Apr 2007
Posts: 60
Thanks: 3
Thanked 0 Times in 0 Posts
tunayx is an unknown quantity at this point
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>
tunayx is offline   Reply With Quote
Old 12-25-2012, 04:35 PM   PM User | #2
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,461
Thanks: 52
Thanked 457 Times in 455 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
you should validate your html

lots of minor stuff, but I suspect the major problem here is not closing your form tags
xelawho is offline   Reply With Quote
Old 12-25-2012, 05:09 PM   PM User | #3
tunayx
New Coder

 
Join Date: Apr 2007
Posts: 60
Thanks: 3
Thanked 0 Times in 0 Posts
tunayx is an unknown quantity at this point
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.
tunayx is offline   Reply With Quote
Old 12-25-2012, 06:17 PM   PM User | #4
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,461
Thanks: 52
Thanked 457 Times in 455 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
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
xelawho is offline   Reply With Quote
Old 12-25-2012, 06:38 PM   PM User | #5
tunayx
New Coder

 
Join Date: Apr 2007
Posts: 60
Thanks: 3
Thanked 0 Times in 0 Posts
tunayx is an unknown quantity at this point
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();
}
}
tunayx is offline   Reply With Quote
Old 12-25-2012, 07:08 PM   PM User | #6
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,461
Thanks: 52
Thanked 457 Times in 455 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
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();
		}
	}
}
xelawho is offline   Reply With Quote
Old 12-25-2012, 07:29 PM   PM User | #7
tunayx
New Coder

 
Join Date: Apr 2007
Posts: 60
Thanks: 3
Thanked 0 Times in 0 Posts
tunayx is an unknown quantity at this point
I implied your code but now return key doesn't work for wikipedia search box.
tunayx is offline   Reply With Quote
Old 12-25-2012, 08:00 PM   PM User | #8
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,461
Thanks: 52
Thanked 457 Times in 455 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
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..
xelawho is offline   Reply With Quote
Old 12-25-2012, 08:05 PM   PM User | #9
tunayx
New Coder

 
Join Date: Apr 2007
Posts: 60
Thanks: 3
Thanked 0 Times in 0 Posts
tunayx is an unknown quantity at this point
I put the new code on a new page same issue with IE 8
tunayx is offline   Reply With Quote
Old 12-25-2012, 08:32 PM   PM User | #10
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,461
Thanks: 52
Thanked 457 Times in 455 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
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();
	}
}
xelawho is offline   Reply With Quote
Users who have thanked xelawho for this post:
tunayx (12-25-2012)
Old 12-25-2012, 08:55 PM   PM User | #11
tunayx
New Coder

 
Join Date: Apr 2007
Posts: 60
Thanks: 3
Thanked 0 Times in 0 Posts
tunayx is an unknown quantity at this point
Okay works perfect. Thanks thousands for your help and patience.

Last edited by tunayx; 12-25-2012 at 09:14 PM..
tunayx is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:19 AM.


Advertisement
Log in to turn off these ads.