PDA

View Full Version : setfocus after onchange method


tanpl3
01-06-2005, 10:05 AM
for example, i have one combo box called cbodept, one text box called txtName. is there any way to set focus to txtName after onchange method set ad cbodept?

eg

function chgdept()
{
document.location ="./abc.asp?tem="+document.forms.cbodept.value;
document.forms.txtName.focus();
}

but it does not work!! please help

jbot
01-06-2005, 10:13 AM
is there a form called "forms". if not, then you want to change the line document.forms.txtName.focus(); to document.forms[0].txtName.focus(); or else to document.formName.txtName.focus(); where formName equals the name of the form.

glenngv
01-06-2005, 10:18 AM
But even then the focus will still not work as the page already went to another URL.

document.location ="./abc.asp?tem="+document.forms.cbodept.value;
document.forms[0].txtName.focus();

jbot
01-06-2005, 10:27 AM
But even then the focus will still not work as the page already went to another URL.

oh yeah ... my bad. never noticed that. :p

tanpl3
01-07-2005, 12:37 AM
actuall the program is like this
<html>
<script language="javascript">
function chgdept()
{
document.location ="./abc.asp?tem="+document.form1.cbodept.value;
document.form1.txtName.focus();
}
</script>
<body>
<form name="form1">
<select name="cboDept" onchange="chgdept()">
..../some code here
</select>

<input type ="text" name="txtNewdept" value ="<%=request("tem")%>">
<input type ="text" name="txtName">

</form></body>
</html>

and this program is call "abc.asp"

glenngv
01-07-2005, 01:30 AM
Even if it will go to the same page, the focus will not work because the page has reloaded. What you need to do is set focus to the text field on onload.

<script language="javascript">
function chgdept()
{
document.location ="./abc.asp?tem="+document.form1.cbodept.value;
}
</script>
<body onload="document.form1.txtName.focus();">