PDA

View Full Version : Simulate Tabbing


jonathan
09-19-2002, 05:04 PM
Hi,
I'm working with layers(div) that have forms on each one. When you click on a button to show/hide a layer, I want it to also set the focus to the first field element on the layer. This would be fine and dandy if some of them are not in a fieldset, but some of them are. From what I gathered you couldn't set focus to a field within a fieldset just by useing the element position in a form. So to get around this I put a invisible(transparent everything) field before the fieldset. So now I was wondering if it would be possible to sort of tab over like it would do if someone pressed the tab key on that field. I'm open for anything.

beetle
09-19-2002, 07:14 PM
Uh, this works fine for me<html>
<body onLoad="document.forms[0].elements[0].focus();">
<fieldset>
<legend>tester</legend>
<form name="form1" id="form1">
<input type="text" name="t1" id="t1" /><br />
<input type="text" name="t2" id="t2" /><br />
<input type="text" name="t3" id="t3" /><br />
</form>
</fieldset>
</body>
</html>These worked toodocument.forms[0].elements['t1'].focus();
document.forms['form1'].elements[0].focus();
document.forms['form1'].elements['t1'].focus();
document.form.t1.focus(); // Requires 'name' attributes
document.getElementById('form1').elements[0].focus();
document.getElementById('form1').elements['t1'].focus();
document.getElementById('t1').focus();So, what is the problem with the fieldset? :confused:

jonathan
09-19-2002, 07:22 PM
Oh, sorry. I just have a couple fields within the fieldset, not the entire form. Though I never really thought about putting the form in the fieldset. The other part is that the name within the fieldset wont be the same all the time, and I was trying to make a code that would work on any layer. This gives me an idea though, I'll see what I can come up with. Thanks.

jonathan
09-19-2002, 08:25 PM
Well I looked more into it and I have something that will work in Explorer but not in netscape. I still can't get the focus on the element within the fieldset but I can get the focus on the fieldset(IE only). I'm trying all sorts of way to work around this but the blank field before the fieldset seems to be the only way. Looking for a better approach than this. Oh, and I'm trying it out on Netscape 6.2.

beetle
09-19-2002, 08:59 PM
Ok, I redid the form like this<html>
<body onLoad="document.getElementsByTagName('INPUT').item(1).focus();">

<form name="form1" id="form1">
<input type="text" name="t1" id="t1" /><br />
<fieldset>
<legend>tester</legend>
<input type="text" name="t2" id="t2" /><br />
</fieldset>
<input type="text" name="t3" id="t3" /><br />
</form>

</body>
</html> And ran the same tests, plus one moredocument.forms[0].elements['t2'].focus(); // Works
document.forms['form1'].elements[1].focus(); // Doesn't Work
document.forms['form1'].elements['t2'].focus(); // Works
document.form.t2.focus(); // Doesn't Work
document.getElementById('form1').elements[1].focus(); // Doesn't Work
document.getElementById('form1').elements['t2'].focus(); // Works
document.getElementById('t2').focus(); // Works
document.getElementsByTagName('INPUT').item(1).focus(); // WorksHope this helps