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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Dec 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How do I set focus using a variable?

    Hello -
    I am new to javascript so all apologies -

    Goal - to set focus to a form element when loading an asp page - using a variable (form name) passed when posting a form.

    Detail - I have an asp page with a large number of forms wrapped in a div tag with overflow scroll. The user chooses to submit from any one of the forms and then variables (including the unique form name) are posted back to the server and the same page is reloaded. When the page reloads I would like the focus to be set back to the form that the user submitted from.

    I am getting the setfocus to work if I hard code one of the form names (ex. "ab142") and call the function onload:

    <script language=javascript>

    <!--
    function setFocus() {
    document.ab142.thumby.focus();

    }
    // -->
    </script>

    (thumby is a text field name common to each form)

    However, I haven't been able to figure out how to include the form name variable (focform) in the document.forms element.

    I have set the variable name as follows:

    <%set focusform = request.form("graphicname")%>

    <script language=javascript>
    var focform = '<%=focusform%>';
    </script>

    Can anyone help me with the code that would create the focus statement using the passed form name variable value?

    Thanks very much!

    Dan

  • #2
    Senior Coder
    Join Date
    Nov 2006
    Posts
    1,000
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try

    document.forms[focform].thumby.focus();

    david_kw

  • #3
    New to the CF scene
    Join Date
    Dec 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It works!

    Thanks again!!!


  •  

    Posting Permissions

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