IE autocomplete and default button bind

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bc

    #1

    IE autocomplete and default button bind

    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 -

    // Available at http://www.gotdotnet.com/Community/W...9-276f0620589d
    string theImageScript = @"
    <SCRIPT language=""java script"">
    <!--
    function fnTrapKD(btnID, event){
    btn = findObj(btnID);
    if (document.all){
    if (event.keyCode == 13){
    event.returnVal ue=false;
    event.cancel = true;
    btn.click();
    }
    }
    else if (document.getEl ementById){
    if (event.which == 13){
    event.returnVal ue=false;
    event.cancel = true;
    btn.focus();
    btn.click();
    }
    }
    else if(document.lay ers){
    if(event.which == 13){
    event.returnVal ue=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.l ength) {
    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.fo rms.length;i++)
    x=d.forms[i][n];
    for(i=0;!x&&d.l ayers&&i<d.laye rs.length;i++)
    x=findObj(n,d.l ayers[i].document);
    if(!x && d.getElementByI d)
    x=d.getElementB yId(n);
    return x;
    }
    // -->
    </SCRIPT>";

    textControl.Att ributes.Add("on keydown", "fnTrapKD(' " +
    defaultButton.C lientID + "',event)") ;
    thisPage.Regist erStartupScript ("ForceDefaultT oScriptImage",
    theImageScript) ;
  • bc

    #2
    Re: IE autocomplete and default button bind

    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@usa.net (bc) wrote in message news:<dfa9e38.0 503040316.1f5af f1c@posting.goo gle.com>...[color=blue]
    > 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=""java script"">
    > <!--
    > function fnTrapKD(btnID, event){
    > btn = findObj(btnID);
    > if (document.all){
    > if (event.keyCode == 13){
    > event.returnVal ue=false;
    > event.cancel = true;
    > btn.click();
    > }
    > }
    > else if (document.getEl ementById){
    > if (event.which == 13){
    > event.returnVal ue=false;
    > event.cancel = true;
    > btn.focus();
    > btn.click();
    > }
    > }
    > else if(document.lay ers){
    > if(event.which == 13){
    > event.returnVal ue=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.l ength) {
    > 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.fo rms.length;i++)
    > x=d.forms[i][n];
    > for(i=0;!x&&d.l ayers&&i<d.laye rs.length;i++)
    > x=findObj(n,d.l ayers[i].document);
    > if(!x && d.getElementByI d)
    > x=d.getElementB yId(n);
    > return x;
    > }
    > // -->
    > </SCRIPT>";
    >
    > textControl.Att ributes.Add("on keydown", "fnTrapKD(' " +
    > defaultButton.C lientID + "',event)") ;
    > thisPage.Regist erStartupScript ("ForceDefaultT oScriptImage",
    > theImageScript) ;[/color]

    Comment

    • c.anandkumar@gmail.com

      #3
      Re: IE autocomplete and default button bind

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

      Thanks

      Anand

      Comment

      • bc

        #4
        Re: IE autocomplete and default button bind

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

        /bc

        "c.anandkumar@g mail.com" <c.anandkumar@g mail.com> wrote in message news:<111018565 1.079452.258050 @f14g2000cwb.go oglegroups.com> ...[color=blue]
        > If you want to turn off IE's autocomplete feature, add
        > autocomplete="o ff" attribute to the input field that you want to use.
        >
        > Thanks
        >
        > Anand[/color]

        Comment

        • Matthew Lock

          #5
          Re: IE autocomplete and default button bind

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

          In IE 6 at least document.getEle mentById('name_ input').autocom plete
          will return "off" if the name_input element contains
          autocomplete="o ff".

          If autocomplete isn't disabled then
          document.getEle mentById('name_ input').autocom plete just returns
          undefined. Maybe you could use that as a basis of some detection code.

          Note that in Firefox document.getEle mentById('name_ input').autocom plete
          always returns undefined.

          Comment

          Working...