Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Object error

Status
Not open for further replies.

thysonj

Programmer
Jul 6, 2001
240
US
Why do I get an "object doesn't sopport this property or method" error witht he code below?

Code:
function setfocus(field)
{
str = 'document.grid.' + field
str.focus();	
}

The field is dynamic but the form will stay the same.
 
because "str" is a string, not an element.

try this instead:
Code:
function setfocus(field)
{
el = document.grid.elements[ field ];
el.focus();    
}

=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); } finally { rtfm(); }
 
Unless the "field" parameter is an object, such as 'this'.

Then you'll have to do:

function setfocus(field) {
document.grid.elements[field].focus();
el.focus();
}

*cLFlaVA
----------------------------
Ham and Eggs walks into a bar and asks, "Can I have a beer please?"
The bartender replies, "I'm sorry, we don't serve breakfast.
 
or:
function setfocus(field)
{
str = 'document.grid.' + field+'.focus()';
eval(str);
}


Known is handfull, Unknown is worldfull
 

Although a valid alternative, I would seriously avoid the use of eval, as it is unnecessary, and is a lot slower than other methods presented.

Hope this helps,
Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top