HighDots Forums  

IE autocomplete and default button bind

Javascript JavaScript language (comp.lang.javascript)


Discuss IE autocomplete and default button bind in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
bc
 
Posts: n/a

Default IE autocomplete and default button bind - 03-04-2005 , 06:16 AM






Hi,
Is it possible to detect if the IE autocomplete function in a current
context such as a textbox is activated (ie. dropdown with previously
entered info is visible)?

Problem:
I use a script as a basis for binding <enter> in textbox to a button,
BUT <enter> in the dropdown autocomplete generated by IE also triggers
this event.
The script is available below (in .NET context but the idea should
shine through).

Best regards
Brian Christensen


// Sets default buttons.
// Originally created by Janus Kamp Hansen - http://www.kamp-hansen.dk
// Extended by Darrell Norton -
http://dotnetjunkies.com/weblog/darrell.norton/
// Available at http://www.gotdotnet.com/Community/W...9-276f0620589d
string theImageScript = @"
<SCRIPT language=""javascript"">
<!--
function fnTrapKD(btnID, event){
btn = findObj(btnID);
if (document.all){
if (event.keyCode == 13){
event.returnValue=false;
event.cancel = true;
btn.click();
}
}
else if (document.getElementById){
if (event.which == 13){
event.returnValue=false;
event.cancel = true;
btn.focus();
btn.click();
}
}
else if(document.layers){
if(event.which == 13){
event.returnValue=false;
event.cancel = true;
btn.focus();
btn.click();
}
}
}

function findObj(n, d) {
var p,i,x;
if(!d)
d=document;
if((p=n.indexOf(""?""))>0 && parent.frames.length) {
d=parent.frames[n.substring(p+1)].document;
n=n.substring(0,p);
}
if(!(x=d[n])&&d.all)
x=d.all[n];
for (i=0;!x&&i<d.forms.length;i++)
x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++)
x=findObj(n,d.layers[i].document);
if(!x && d.getElementById)
x=d.getElementById(n);
return x;
}
// -->
</SCRIPT>";

textControl.Attributes.Add("onkeydown", "fnTrapKD('" +
defaultButton.ClientID + "',event)");
thisPage.RegisterStartupScript("ForceDefaultToScri ptImage",
theImageScript);

Reply With Quote
  #2  
Old   
bc
 
Posts: n/a

Default Re: IE autocomplete and default button bind - 03-07-2005 , 03:04 AM






Doesn't anybody have an idea on where to proceed? If there are
alternate groups that might be able to help me out I'd appreciate if
someone post them..

Thanks...

/brian

bc_aux (AT) usa (DOT) net (bc) wrote in message news:<dfa9e38.0503040316.1f5aff1c (AT) posting (DOT) google.com>...
Quote:
Hi,
Is it possible to detect if the IE autocomplete function in a current
context such as a textbox is activated (ie. dropdown with previously
entered info is visible)?

Problem:
I use a script as a basis for binding <enter> in textbox to a button,
BUT <enter> in the dropdown autocomplete generated by IE also triggers
this event.
The script is available below (in .NET context but the idea should
shine through).

Best regards
Brian Christensen


// Sets default buttons.
// Originally created by Janus Kamp Hansen - http://www.kamp-hansen.dk
// Extended by Darrell Norton -
http://dotnetjunkies.com/weblog/darrell.norton/
// Available at http://www.gotdotnet.com/Community/W...9-276f0620589d
string theImageScript = @"
SCRIPT language=""javascript""
!--
function fnTrapKD(btnID, event){
btn = findObj(btnID);
if (document.all){
if (event.keyCode == 13){
event.returnValue=false;
event.cancel = true;
btn.click();
}
}
else if (document.getElementById){
if (event.which == 13){
event.returnValue=false;
event.cancel = true;
btn.focus();
btn.click();
}
}
else if(document.layers){
if(event.which == 13){
event.returnValue=false;
event.cancel = true;
btn.focus();
btn.click();
}
}
}

function findObj(n, d) {
var p,i,x;
if(!d)
d=document;
if((p=n.indexOf(""?""))>0 && parent.frames.length) {
d=parent.frames[n.substring(p+1)].document;
n=n.substring(0,p);
}
if(!(x=d[n])&&d.all)
x=d.all[n];
for (i=0;!x&&i<d.forms.length;i++)
x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++)
x=findObj(n,d.layers[i].document);
if(!x && d.getElementById)
x=d.getElementById(n);
return x;
}
// --
/SCRIPT>";

textControl.Attributes.Add("onkeydown", "fnTrapKD('" +
defaultButton.ClientID + "',event)");
thisPage.RegisterStartupScript("ForceDefaultToScri ptImage",
theImageScript);

Reply With Quote
  #3  
Old   
c.anandkumar@gmail.com
 
Posts: n/a

Default Re: IE autocomplete and default button bind - 03-07-2005 , 03:54 AM



If you want to turn off IE's autocomplete feature, add
autocomplete="off" attribute to the input field that you want to use.

Thanks

Anand


Reply With Quote
  #4  
Old   
bc
 
Posts: n/a

Default Re: IE autocomplete and default button bind - 03-08-2005 , 08:28 AM



Tnx for suggestion! But I don't want to hack the solution by disabling
functionality, e.g by putting autocomplete="off" on my control, but
instead detect it. Can it be done via javascript?

/bc

"c.anandkumar (AT) gmail (DOT) com" <c.anandkumar (AT) gmail (DOT) com> wrote

Quote:
If you want to turn off IE's autocomplete feature, add
autocomplete="off" attribute to the input field that you want to use.

Thanks

Anand

Reply With Quote
  #5  
Old   
Matthew Lock
 
Posts: n/a

Default Re: IE autocomplete and default button bind - 03-08-2005 , 07:51 PM



The best I was able to do was detect if autocomplete was disabled.

In IE 6 at least document.getElementById('name_input').autocomplete
will return "off" if the name_input element contains
autocomplete="off".

If autocomplete isn't disabled then
document.getElementById('name_input').autocomplete just returns
undefined. Maybe you could use that as a basis of some detection code.

Note that in Firefox document.getElementById('name_input').autocomplete
always returns undefined.


Reply With Quote
Reply




Thread Tools
Display Modes

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

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



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.