Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6030545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:03:08+00:00 2026-05-23T05:03:08+00:00

For some reason none of my setfocus() events were working on the server side

  • 0

For some reason none of my setfocus() events were working on the server side of my web app, so I created a Javascript function setfocus that is set to trigger on the onload event of the body tag.

<body onload="SetFocus()">

The user will click a radio button which enables the drop down. they select from the drop down which enables the textbox. When they scan a barcode into the textbox it will automatically tab out of the field, therefore triggering the onchange event to call some server side code which, if a successful SQL insert is completed, will insert a new row to the gridview, and it should set focus automatically back to the textbox via Javascript. Once that gridview object has more than a header and a row of data, I disable the drop down and radio button list, so if you look at the Javascript below, I can’t use those as criteria in my if statement anymore.

Javascript:

 var MatAllRB = document.getElementById("HF_RB_MatAll").value;
 var MatAllCL = document.getElementById("DD_SelectCL_All").value;
 var MatAll = document.getElementById("Txt_MatBC_All");
 var MatAllPrompt = document.getElementById("HF_AllPrompt").value;
 var count = $("#GV_Scan_All tr").children().length;
        

This works perfectly:

else if (ActiveTab == "cont-3" && MatAllRB != "" && MatAllCL != "")
    {   alert("went into setfocus");
        document.getElementById("Txt_MatBC_All").focus();
        alert("made it through setfocus");
    }

This only works if you actually click off the field, the tab doesn’t work. It just does nothing.

else if (ActiveTab == "cont-3" && count == 9)
    {   alert("went into setfocus");
        document.getElementById("Txt_MatBC_All").focus();
        alert("made it through setfocus");
    }

This does the same thing as the above:

else if (ActiveTab == "cont-3" && (MatAllPrompt == "RP" || MatAllPrompt == "P03"))
    {   alert("went into setfocus");
        document.getElementById("Txt_MatBC_All").focus();
        alert("made it through setfocus");
    }

The weird thing is that all of these alerts that I have in here show up correctly, it just never sets focus. I am pretty new at this stuff still, so maybe I’m missing something, but I can’t figure out why the focus() will work for click off rather than tabbing off. Any help would be appreciated.

Here’s the HTML:

    <asp:RadioButtonList runat="server" ID="RB_Mat_All" AutoPostBack="true" RepeatColumns="4" OnSelectedIndexChanged="RB_Mat_All_OnSelectedIndexChange">
    <asp:ListItem Text="NC" value="NC"></asp:ListItem>
    <asp:ListItem Text="DA" value="DA"></asp:ListItem>
    <asp:ListItem Text="GW" value="GW"></asp:ListItem>
    <asp:ListItem Text="PC" value="PC"></asp:ListItem>
</asp:RadioButtonList>
<asp:HiddenField runat="server" ID="HF_RB_MatAll"></asp:HiddenField >
<br />
<asp:DropDownList runat="server" ID="DD_SelectCL_All" AutoPostBack="true" OnSelectedIndexChanged="DD_SelectCL_All_OnSelectedIndexChange">
    <asp:ListItem Value="" Text="Select..."></asp:ListItem>
    <asp:ListItem value="53" text="05"></asp:ListItem>
    <asp:ListItem value="54" text="06"></asp:ListItem>
    <asp:ListItem value="55" text="07"></asp:ListItem>
    <asp:ListItem value="57" text="08"></asp:ListItem>
    <asp:ListItem value="58" text="09"></asp:ListItem>
</asp:DropDownList>
<asp:label runat="server" ID="Lbl_All_Prompt" CssClass="Form" Text=""></asp:label>
<asp:HiddenField runat="server" ID="HF_AllPrompt"></asp:HiddenField >
<asp:TextBox runat="server" ID="Txt_MatBC_All" Cssclass="Form" Text="" AutoPostBack="true" OnTextChanged="Txt_MatBC_All_TextChanged"></asp:TextBox>
<asp:GridView runat="server" ID="GV_Scan_All" CssClass="Form_Feedback"></asp:GridView>

When I view the source the textbox looks like this:

<input name="Txt_MatBC_All" type="text" onchange="javascript:setTimeout(&#39;__doPostBack(\&#39;Txt_MatBC_All\&#39;,\&#39;\&#39;)&#39;, 0)" onkeypress="if (WebForm_TextBoxKeyHandler(event) == false) return false;" id="Txt_MatBC_All" class="Form" />
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T05:03:09+00:00Added an answer on May 23, 2026 at 5:03 am

    It’s odd that you can click off the field and it works, but tabbing off doesn’t. Try adding tabIndexes to the inputs on your page.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, none of my UITextFields will autocapitalize. I have set the property
for some reason after having changed my code from this: <script type=text/javascript> $(document).ready(function(){ $(recipebutton1).click(function(){
For some reason, none of my figures properly display the axis labels set in
For some reason none of these DIVs render disabled. Oddly enough, when I set
For some reason, this line of code is returning undefined for $(this).attr(href) $(a).attr(href, javascript:page('
For some reason I can't detect I can't set a z index for any
For some reason there's a variable called d that is defined immediately after I
For some reason this isn't working, am I missing something obvious? RewriteRule ^(.*)infopopup.html$ /acatalog/infopopup.html
For some reason, my spec isn't passing. It appears that @categories isn't getting to
I have built several websites, and for some reason none of them will post

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.