Advertisement

05.11.2004 at 09:41AM PDT, ID: 20985576
[x]
Attachment Details

Focus to an Text Input

Asked by BenSwitzer in JavaScript

Tags: javascript, focus, input

Currently I am taking a value from a text box, validating that it is a known value(only certain values can be entered), then if it is not within the select box I add the value to the select box, then whipe out the text value.  I have tried to give the focus back to the text box after all of this, but it never happens.  here is the code.

<script language="Javascript">
var uicstr;
function popUicArray(thestr)
{
  uicstr = thestr;
}
function findUic(theuic)
{
 if(theuic != "")
 {
   var found = uicstr.indexOf(theuic);
  // alert(uicstr + ' ' + theuic);
   if(notinfinal(theuic))
    {
     if(found != -1)
     {
       CPOCommandForm.uic.length++;
       CPOCommandForm.uic[CPOCommandForm.uic.length-1].text = theuic;
      CPOCommandForm.entryuic.value = "";
       CPOCommandForm.entryuic.focus();  
     }
     else
     {
     alert("That uic could not be found. Please try again.");
     }
   }
 }
 else
     CPOCommandForm.entryuic.focus();

CPOCommandForm.entryuic.focus();  
}
function notinfinal(theuic)
{
   for (var i=0; i < CPOCommandForm.uic.options.length; i++)
   {

    if(CPOCommandForm.uic.options[i].text == theuic)
    {
     //found that uic in the list so return false
      return false;
    }
  }
   //  was not in the list
   return true;
}
</script>

The uicstr is populated earlier. Here is how the text input calls the function:
<td valign="top" align="left">
  <input type="text" name="entryuic" onchange="findUic(this.value)"   size="5" maxlength="5">
</td>
 <td>
<select name="uic" style="height: 150px" size="5" onDblClick="removeSelection(CPOCommandForm.uic.selectedIndex)"></select></td>

Any Ideas?

Thanks
Ben SwitzerStart Free Trial
[+][-]05.11.2004 at 05:06PM PDT, ID: 11045743

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.11.2004 at 05:10PM PDT, ID: 11045781

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: JavaScript
Tags: javascript, focus, input
Sign Up Now!
Solution Provided By: Zvonko
Participating Experts: 1
Solution Grade: A
 
 
[+][-]05.12.2004 at 06:11AM PDT, ID: 11049491

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.12.2004 at 06:21AM PDT, ID: 11049593

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.12.2004 at 06:33AM PDT, ID: 11049705

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32