Welcome guest, is this your first visit? Create Account now to join.
Results 1 to 2 of 2

This is a discussion on Javascript Set Focus Code Not Working within the Chrome Troubleshooting section, part of the Google Chrome category: All the lines of code in the following function enteringRentAmt(sender,args), are working except "ctlNumYears.focus();" If there's an entry in txtRentAmt, ...


  1. #1
    Zimbello is offline Junior Member
    Join Date
    Aug 2010
    Posts
    1

    Default Javascript Set Focus Code Not Working

    All the lines of code in the following function enteringRentAmt(sender,args), are working except "ctlNumYears.focus();" If there's an entry in txtRentAmt, the txtRentNumberYearAmt box should be enabled and get focus. Instead, it is enabled but the focus goes to the next textbox after it (txtLoans). Works in IE8 and FF, not in Chrome or Safari.
    Suggestions appreciated.
    <script type="text/javascript">
    function enteringRentAmt(sender, args)
    {
    var ctlNumYears;
    var ctlRentAmt;
    var ctlLoans;
    args.IsValid = true;
    ctlNumYears = document.getElementById("<%=txtRentNumberYearAmt.ClientID%");
    ctlRentAmt = document.getElementById("<%=txtRentAmt.ClientID%>");
    ctlLoans = document.getElementById("<%=txtLoansAmt.ClientID%>");

    if (args.Value.length > 0)
    {
    //enable No. of Years
    ctlNumYears.disabled = false;
    ctlNumYears.focus();
    }
    else
    {
    ctlNumYears.value = "";
    ctlRentAmt.focus();
    ctlNumYears.disabled = true;
    ctlLoans.focus();
    }

    } // end of enteringRentAmt
    </script>

  2. #2
    djs
    djs is offline Junior Member
    Join Date
    Aug 2010
    Posts
    1

    Default work around for issue

    You can use a window.setTimeout set to 0 to work around the issue and get the focus in the corrrect place. The code that worked for me to set focus correctly is below. Note this worked where just setting the focus without it being inside the
    Code:
    window.setTimeout
    call did not.


    Code:
        function comparePassword()
        {
        var password = document.form1.password.value;
        var confirmpassword = document.form1.confirmpassword.value;
        
        if (password != confirmpassword)
        	{
        	// document.form1.email.disabled = "true";
        	alert("Passwords do not match, please try again");
        	document.form1.confirmpassword.value = "";
        	document.form1.password.value = "";
        	
        	window.setTimeout(function()
        			{
        			document.form1.password.focus();
        			},0);
    
        	}
        }

Similar Threads

  1. Focus address bar or content
    By a2720286 in forum Plugins Development
    Replies: 3
    Last Post: 04-09-2010, 12:44 PM
  2. Shift focus from webpage to Chrome
    By BordrGuy108 in forum Chrome Tips & Tricks
    Replies: 1
    Last Post: 11-29-2009, 07:10 PM
  3. Free JavaScript Code Downloads
    By JavaScriptBank in forum General Chat
    Replies: 1
    Last Post: 09-30-2009, 07:18 AM
  4. Site homepage with some bad code?
    By NicholasPufal in forum Chrome Central
    Replies: 12
    Last Post: 07-19-2009, 09:57 AM
  5. Simple javascript not working - OK on Firefox, IE etc,
    By Skibrowse in forum Bugs and Vulnerabilities
    Replies: 0
    Last Post: 04-17-2009, 10:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •