Hello all,
I have a few '<input type="text" />' controls on my ASP.NET 2.0 generated page.
Every text-box control has it's specific tab-index.
When I try to move focus to this specific text-box control on this page the focus is shifted to the window element instead of the control itself.
On every other text-box control on the page the focus is received fine.
To apply focus to this element I use the code:

document.all.elemName.focus();

This is the control itself:

<input name       = "ctl00$EditMasterContent$c_carats"
           type       = "text"
           maxlength  = "10"
           id         = "ctl00_EditMasterContent_c_carats"
           tabindex   = "6"
           class      = "textbox1"
           onchange   = "registerOnChangeAction(&quot;caratsChanged&quot;);"
           onkeypress = "javascript:ChkNumberKeyPress(false);"
           onfocus    = "initFocusedElementsVar(this.id);"
           style      = "width: 100px;" />

Some other text-box control on the page:

<input name       = "ctl00$EditMasterContent$c_stones"
           type       = "text"
           maxlength  = "5"
           id         = "ctl00_EditMasterContent_c_stones"
           tabindex   = "5"
           class      = "textbox1"
           onchange   = "registerOnChangeAction(&quot;stonesChanged&quot;);"
           onkeypress = "javascript:ChkNumberKeyPress(false);"
           onfocus    = "initFocusedElementsVar(this.id);"
           style      = "width: 100px;" />
Attachments
<html xmlns="http://www.w3.org/1999/xhtml">
  <head><title>

</title>
    <script language="javascript" type="text/javascript">
        var m_inputFormatExceptionThrown = false;
        var m_inputFormatExceptionSource = "";

        var m_caratDigits_left;
        var m_caratDigits_right;
        var m_stoneDigits_left;
        var m_stoneDigits_right;
        var m_percentageDigits_left;
        var m_percentageDigits_right;
        var m_priceDigits_left;
        var m_priceDigits_right;
        var m_amountDigits_left;
        var m_amountDigits_right;

        function getIdentity() { return "MNWebApp.PreExport.itemsInnerTabFillDetailsEdit"; }

        function showDebugInfo(message)
        {
            var l_debugMsgLabel = document.getElementById("ctl00_EditMasterContent_c_lbl_debugInfo");
            l_debugMsgLabel.innerHTML += message;
        }
        function dummyFunc() { alert("moo"); }

        function CloseEditWindow()
        {
            var str = parent.getEditFrameContainer();
            HideParentItemsInnerTabEditContainer(str); // in generalScripts.js
        }

        var m_focusCurr = null;
        var m_focusPrev = null;
        function initFocusedElementsVar(elemID)
        {
            showDebugInfo("initFocusedElementsVar(" + elemID + ")<br />");
            m_focusPrev = m_focusCurr;
            m_focusCurr = document.getElementById(elemID);
          // If any onchange action has been registered, it will be called right here
            if (m_nextAction != null && m_nextAction != "")
            {
                actionMapper();
                m_nextAction = "";
            }
        }

        function setInputFocus(inputID)
        {
            showDebugInfo("setInputFocus('" + inputID + "')");
            switch(inputID)
            {
                case "ctl00_EditMasterContent_c_stones":     document.all.ctl00_EditMasterContent_c_stones.focus();     break;
                case "ctl00_EditMasterContent_c_carats":     document.all.ctl00_EditMasterContent_c_carats.focus();     break;
                case "ctl00_EditMasterContent_c_percentage": document.all.ctl00_EditMasterContent_c_percentage.focus(); break;
                case "ctl00_EditMasterContent_c_price":      document.all.ctl00_EditMasterContent_c_price.focus();      break;
                case "ctl00_EditMasterContent_c_amount":     document.all.ctl00_EditMasterContent_c_amount.focus();     break;
            }
        }

        function ReloadParentPage(closeThisWindow)
        {
            parent.ReloadGridPage();

            if (closeThisWindow) { CloseEditWindow(); }
        }

        var m_newStones;
        var m_initialStones;
        function getNewStonesvalue()
        {
            m_newStones = parseInt(document.all.ctl00_EditMasterContent_c_stones.value);
        }
        var m_newCarats;
        var m_initialCarats;
        function getNewCaratsValue()
        {
            m_newCarats = parseFloat(document.all.ctl00_EditMasterContent_c_carats.value);
        }
        var m_newPercentage;
        var m_initialPercentage;
        function getNewPercentageValue()
        {
            m_newPercentage = parseFloat(document.all.ctl00_EditMasterContent_c_percentage.value);
        }
        var m_newPrice;
        var m_initialPrice;
        function getNewPriceValue()
        {
            m_newPrice = parseFloat(document.all.ctl00_EditMasterContent_c_price.value);
        }
        var m_newAmount;
        var m_initialAmount;
        function getNewAmountValue()
        {
            m_newAmount = parseFloat(document.all.ctl00_EditMasterContent_c_amount.value);
        }
        function roundMyNumber(arg_number)
        {
            if(!isFinite(arg_number))
                return 0;
            
            return ( ( Math.round(( parseFloat(arg_number) ) * 1000)) / 1000);
        }
        function valueIsZero(fieldName, value)
        {
            if(parseFloat(value) == 0)
            {
                alert("WARNING! Hidden Field: \"" + fieldName + "\" cannot have a \"0\" value.\n" +
                      "Please contact: \'support@moshenamdar.com\'");
                return true;
            }
            return false;
        }
      //  Setting the pricing mode to either "Price Per..." or "Percent Below/Above..."
        var m_pricingMode = "PricePerCarat";
        function changePricingMode(priceMode)
        {
            if      (priceMode == "PricePerCarat")
            {
                m_pricingMode = "PricePerCarat";
                document.all.ctl00_EditMasterContent_c_calcField1.selectedIndex = 0;
                document.all.ctl00_EditMasterContent_c_percentage.value         = "0";
                if(!m_pageIsDisabled)
                {
                    document.all.ctl00_EditMasterContent_c_calcField1.disabled = false;
                    document.all.ctl00_EditMasterContent_c_percentage.disabled = false;
                }
                getSelectedCalcField1Item();
            }
            else if (priceMode == "PricePerStoneOrAmount")
            {
                m_pricingMode = "PricePerStoneOrAmount";
                document.all.ctl00_EditMasterContent_c_calcField1.selectedIndex = 0;
                document.all.ctl00_EditMasterContent_c_calcField1.disabled      = true;
                document.all.ctl00_EditMasterContent_c_percentage.value         = "0";
                document.all.ctl00_EditMasterContent_c_percentage.disabled      = true;
                getSelectedCalcField1Item();
            }
            else if (priceMode == "PercentBelowAbove")
            {
                m_pricingMode = "PercentBelowAbove";
                document.all.ctl00_EditMasterContent_c_priceType.selectedIndex = 0;
                if(!m_pageIsDisabled)
                {
                    document.all.ctl00_EditMasterContent_c_calcField1.disabled = false;
                    document.all.ctl00_EditMasterContent_c_percentage.disabled = false;
                }
            }
        }

    ////////////////////////////////////////////////////////////////////////////////////////////////////
    ///////////////////////////////  ^^^^^  ITEM LOOKUP SECTION  ^^^^^  ////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////
        var m_ItemLookupClicked = false;
        function OpenSearchForStockItems() // Item lookup
        {
            m_ItemLookupClicked = true;
            var internalStockID = OpenSearchForItems(document.all.ctl00_EditMasterContent_c_item.value);  // in PreExport.js
            if (internalStockID != 0)
            {
//                showDebugInfo("OpenSearchForStockItems()<br />" +
//                             "&nbsp;&nbsp;internalStockID = <br />" +
//                             "&nbsp;&nbsp;" + internalStockID + "<br />");
                document.all.ctl00_EditMasterContent_hdn_internalStockID.value = internalStockID;
                ctl00_EditMasterContent_ajaxManager.AjaxRequest("LoadStockItem");
                setCursorToWaiting(true); // on 'generalScripts.js'
              // The cursor is reverted back to 'default' through server-size code.
            }
            self.setTimeout('setItemLookupClickedToFalse()', 3000);
        }
        function setItemLookupClickedToFalse()
        {
            m_ItemLookupClicked = false;
        }
        function hideItemLookupImg(flag)
        {
//            if(flag == true)
//                document.all.ctl00_EditMasterContent_c_itemLookupImg.style.display = "none";
//            else
//                document.all.ctl00_EditMasterContent_c_itemLookupImg.style.display = "block";
            if(flag == true)
                document.all.ctl00_EditMasterContent_c_itemLookupImg.style.visibility = "hidden";
            else
                document.all.ctl00_EditMasterContent_c_itemLookupImg.style.visibility = "visible";
        }
    ////////////////////////////////////////////////////////////////////////////////////////////////////
    ///////////////////////////////  vvvvv  ITEM LOOKUP SECTION  vvvvv  ////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////

        
    ////////////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////  ^^^^^  CHECKING INPUT VALIDITY SECTION  ^^^^^  ///////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////
        function ChkNumberKeyPress(allowNegative)
        {
            var strKey    = event.keyCode;
            var inputId   = event.srcElement.id;
            var input     = document.getElementById(inputId);
            var hasAPoint = input.value.indexOf(".", 0);

            if (
                !(
                  ((strKey >= 48) && (strKey <= 57))    || // between '0' and '9'
                  ((strKey == 45) &&  allowNegative)    || // "-"
                  ((strKey == 46) && (hasAPoint == -1))    // "."
                 )
               )
            {
                event.keyCode = 0;
            }
        }
        function floatingPointCheck(inputId, maxLeft, maxRight)
        {
            var myNumber    = Math.pow(10, maxLeft);
            var myDecimal   = Math.pow(10, maxRight);
            var input       = document.getElementById(inputId);
            var inputNum    = parseFloat(input.value);
            var hasAPoint   = input.value.indexOf(".", 0);
            var lodpTooLong = false;  // a flag showing if: left of decimal point is too long
            var rodpTooLong = false;  // a flag showing if: right of decimal point is too long

            if (input.value != "" && isFinite(inputNum))
            {
                if (hasAPoint != -1) // There is a decimal point
                {
                    if (maxRight == 0) // If only integers (who

Try document.forms[0].elements['yourElementName'].focus() . Don't use document.all. It's not a standard property of the document object. And having a 1.8K line source file is bad in itself IMO.

This article has been dead for over six months. Start a new discussion instead.