B
bc
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/Workspaces/Workspace.aspx?id=a3b93959-9b2e-428a-99d9-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[n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++)
x=findObj(n,d.layers.document);
if(!x && d.getElementById)
x=d.getElementById(n);
return x;
}
// -->
</SCRIPT>";
textControl.Attributes.Add("onkeydown", "fnTrapKD('" +
defaultButton.ClientID + "',event)");
thisPage.RegisterStartupScript("ForceDefaultToScriptImage",
theImageScript);
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/Workspaces/Workspace.aspx?id=a3b93959-9b2e-428a-99d9-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[n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++)
x=findObj(n,d.layers.document);
if(!x && d.getElementById)
x=d.getElementById(n);
return x;
}
// -->
</SCRIPT>";
textControl.Attributes.Add("onkeydown", "fnTrapKD('" +
defaultButton.ClientID + "',event)");
thisPage.RegisterStartupScript("ForceDefaultToScriptImage",
theImageScript);