IE autocomplete and default button bind

Discussion in 'Javascript' started by bc, Mar 4, 2005.

  1. bc

    bc Guest

    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);
     
    bc, Mar 4, 2005
    #1
    1. Advertising

  2. bc

    bc Guest

    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) wrote in message news:<>...
    > 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);
     
    bc, Mar 7, 2005
    #2
    1. Advertising

  3. bc

    Guest

    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
     
    , Mar 7, 2005
    #3
  4. bc

    bc Guest

    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

    "" <> wrote in message news:<>...
    > 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
     
    bc, Mar 8, 2005
    #4
  5. bc

    Matthew Lock Guest

    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.
     
    Matthew Lock, Mar 9, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matthias Marx

    HowTo Bind a Imagebutton as default

    Matthias Marx, Dec 3, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    327
    Matthias Marx
    Dec 3, 2003
  2. mr2_93
    Replies:
    1
    Views:
    3,678
    mr2_93
    Oct 2, 2005
  3. Andrew Crowe
    Replies:
    2
    Views:
    16,330
    Jukka K. Korpela
    Feb 6, 2004
  4. AlecL
    Replies:
    2
    Views:
    847
    Alexey Smirnov
    Feb 12, 2007
  5. Replies:
    0
    Views:
    616
Loading...

Share This Page