Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Oct 2004
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    setfocus after onchange method

    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

  • #2
    Senior Coder
    Join Date
    Feb 2004
    Location
    Edinburgh
    Posts
    1,352
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    *keep it simple (TM)

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    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();
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #4
    Senior Coder
    Join Date
    Feb 2004
    Location
    Edinburgh
    Posts
    1,352
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by glenngv
    But even then the focus will still not work as the page already went to another URL.
    oh yeah ... my bad. never noticed that.
    *keep it simple (TM)

  • #5
    New Coder
    Join Date
    Oct 2004
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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"

  • #6
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    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();">
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •