document.getElementById(thisObject) returns null

I have function 'calculate(thisObject)' which is triggered by the OnChange event on a number of textfields:

            ...
            <td>
              <input type="textfield" name="field1" value=0.00
                  onFocus="this.select()"
                  onChange="calculate(this)">
            </td>
            <td>
              <input type="textfield" name="field2" value=0.00
                  onFocus="this.select()"
                  onChange="calculate(this)">
            </td>
            ...

var fzero=0.00;

function calculate(thisObject) {

   <snip - some code to calculate the values of 'w' and 'washed' >

   if (w > washed) {
      alert ("Sample weight can not be larger than Washed Weight" );
      thisObject.value=fzero.toFixed(2);

      // PROBLEM LINE
      setTimeout( document.getElementById(thisObject).focus(), 10 );

  } else {
     document.jobform.TW.value=w.toFixed(2);
  }

}

The problem I have is that although the value gets set correctly in the line "thisObject.value=fzero.toFixed(2)", the line that attempts to set the focus fails with the following error:

   Error:  'document.getElementById(...)' is null or not an object.
   Code: 0

I've tried referencing the object directly:

   setTimeout( thisObject.focus(), 10 );

   Error:  invalid Argument
   Code: 0

...and attempted quoting in various ways ;-) ..but I cant get this code to set the focus correctly without either an error, or placing focus on the next element in the tab sequence.

I'm not a regular JS programmer and its not that important that I get this working, but I'm a bit of a perfectionist.  This is probably basic stuff for all you server-side hackers, and it bugs the hell out of me, so I would appreciate your comments.

Thanks.
LVL 11
siliconbritAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

robotman757Commented:
The problem I believe is that you are missing the id's of the item. To call that function you need to give the object an ID like this:

<td>
              <input type="textfield" name="field1" id="field1" value=0.00
               onFocus="this.select()"
               onChange="calculate(this)">
            </td>
            <td>
              <input type="textfield" name="field2" id="field2" value=0.00
               onFocus="this.select()"
               onChange="calculate(this)">
            </td>

the getElementById function needs an id to work, at least that has been my experience.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
justinbilligCommented:
the set timeout function takes two parameters, the command you want to execute as a string and the time


setTimeout( "thisObject.focus()", 10 );


but your setting the focus to that object in ten miliseconds. the user won't be able to notice the wait ( if that is what your going for )


you could just do this

thisObject.focus( );
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.