iamari
asked on
Unable to set focus on a span
I'm just trying to set focus on a span, like:
<HTML><HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!--
function getFocus(which)
{
// get "null or not an object" with
// document.myForm.wantFocus. focus();
// get nothing with
document.all.wantFocus.foc us();
return false;
}
//-->
</script>
</HEAD><BODY>
<form name="myForm" action="somefile.htm" method="post" onSubmit="return getFocus(this)">
<span id="wantFocus" style="text-decoration : underline; cursor : hand;">I Look like a Link and I want Focus!</span>
<table border="1"><!--- just some empty space to the Submit button --->
<tr height="700"><td> </t d></tr></t able>
<input type="submit" value="Submit">
</form>
</BODY></HTML>
<HTML><HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!--
function getFocus(which)
{
// get "null or not an object" with
// document.myForm.wantFocus.
// get nothing with
document.all.wantFocus.foc
return false;
}
//-->
</script>
</HEAD><BODY>
<form name="myForm" action="somefile.htm" method="post" onSubmit="return getFocus(this)">
<span id="wantFocus" style="text-decoration : underline; cursor : hand;">I Look like a Link and I want Focus!</span>
<table border="1"><!--- just some empty space to the Submit button --->
<tr height="700"><td> </t
<input type="submit" value="Submit">
</form>
</BODY></HTML>
ASKER
hmmm.... funny thing is, if i change it like this, it throws the "null..." error, but it works anyway
(remove the action="somefile.htm" and use document.myForm.wantFocus. focus();
any ideas?
<HTML><HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!--
function getFocus(which)
{
// get "null or not an object" with
document.myForm.wantFocus. focus();
// get nothing with
// document.all.wantFocus.foc us();
return false;
}
//-->
</script>
</HEAD><BODY>
<form name="myForm" method="post" onSubmit="return getFocus(this)">
<span id="wantFocus" style="text-decoration : underline; cursor : hand;">I Look like a Link and I want Focus!</span>
<table border="1"><!--- just some empty space to the Submit button --->
<tr height="700"><td> </t d></tr></t able>
<input type="submit" value="Submit">
</form>
</BODY></HTML>
(remove the action="somefile.htm" and use document.myForm.wantFocus.
any ideas?
<HTML><HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!--
function getFocus(which)
{
// get "null or not an object" with
document.myForm.wantFocus.
// get nothing with
// document.all.wantFocus.foc
return false;
}
//-->
</script>
</HEAD><BODY>
<form name="myForm" method="post" onSubmit="return getFocus(this)">
<span id="wantFocus" style="text-decoration : underline; cursor : hand;">I Look like a Link and I want Focus!</span>
<table border="1"><!--- just some empty space to the Submit button --->
<tr height="700"><td> </t
<input type="submit" value="Submit">
</form>
</BODY></HTML>
It's not a form element, therefore.
It's just not possible.
CJ
It's just not possible.
CJ
yupp. i dont know what more to add.
but does your span have any for elements in them? you should give them focus directly. not through a span.
but does your span have any for elements in them? you should give them focus directly. not through a span.
ASKER
i thought once you id any tag element (id="wantFocus") you can address that tag in script
Yes you can, but that does not mean that you can do everything with it. Every object has several properties and methods that can be accessed, they do not have to be the same for each and every object.
CJ
CJ
ASKER
perhaps you're right, what throws me off is that it actually works (see the second version)
it does set focus on the span, but only if i remove the "action" property on the form tag
it does set focus on the span, but only if i remove the "action" property on the form tag
Did not for me... tried it :-/
CJ
CJ
ASKER
reason i tried <span> instead of <a href="##">:
the link just pops a new window. user selects something in new window, value is passed back to caller window.
using href will also reload the caller page. i want to avoid that.
tried <a id="wantFocus"> this doesn't load the caller, but it doesn't get focus either.
any other way to fix this?
the link just pops a new window. user selects something in new window, value is passed back to caller window.
using href will also reload the caller page. i want to avoid that.
tried <a id="wantFocus"> this doesn't load the caller, but it doesn't get focus either.
any other way to fix this?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks, CJ, it works
CJ
(ps. span's cannot have focus)