Skip navigation
Currently Being Moderated

How to set a form field focus

Jan 22, 2013 7:42 AM

Is there a simple way to set a form field focus... so basically on load the field focus is set to a specific field?  I know how to write it in javascript but was wondering if there is a simple way to basically select the field and click a button or two and get the same result?  thanks.

 
Replies
  • Currently Being Moderated
    Jan 22, 2013 8:16 AM   in reply to rraacc0001

    Do you mean set the focus of a form field within Dreamweaver's Design View interface?

     

    There's no built-in function of DW that I've ever seen, I'm still a few versions back. It's "possible" it was added, but  I don't see this being in such common usage that they would add it though.

     

    You could save the javascript as a Snippet and re-use it that way. In Split View, you would click the form field in the Design View section, then in the Source View, click the exact location you want, then double click the Snippet in the Snippets tab to place it.

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 22, 2013 9:46 AM   in reply to rraacc0001

    How are you currently setting focus of your elements?

     

    Are you placing a javascript in the <body> tag or adding it as a <script> tag after the form?

     

    If you use HTML5, you just set the autofocus attribute within the actual form element and you're done. It's the same no matter what page, form or user input you set it on: autofocus="autofocus"

     

    http://www.w3schools.com/html5/att_input_autofocus.asp

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 22, 2013 11:12 AM   in reply to rraacc0001

    The script for that is extremely small and very simple.

     

    In all hosety, it would probably take longer to edit it through the DW interface than by hand.

     

    Add this after your form and change the bold areas to the name of the form and the name of the input you want to have focus on...

     

    <script type="text/javascript" language="JavaScript">

    document.forms['myform'].elements['mytextfield'].focus();

    </script>

     

    Those two things are the only items that will ever change.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points