PassMark Logo
Home » Forum

Announcement

Collapse
No announcement yet.

Input field active - setting the focus on page load

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Input field active - setting the focus on page load

    Is there a way to make the input field 'active' as soon as the page opens - whether it's the main form page or just a simple form?

    Tim

  • #2
    The browser will normally do this for you. So it is not normally required.

    However if you want to change the default browser behaviour you need to use some additional Javascript code to do this.

    For the sake of an example, imagine that this was your Zoom search form,

    <form method="GET" name="MySearchForm" action="search.php">
    <input type="text" name="zoom_query" size="15">
    <input type="submit" value="Search" name="Button1">
    </form>

    Then you could use Javascript like this to set the position of the cursor (the focus) by adding an onLoad attribute to the <BODY ...> tag.

    <BODY onLoad="document.forms.MySearchForm.zoom_query.focus()">

    --------
    David
    WrenSoft

    Comment


    • #3
      I am trying to achieve the same effect as tj, however, I am using .asp. The browser does not default the cursor either, as was suggested by David and although I have tried applying David's solution (in the body of search_template.html file) I do not get a cursor defaulting to the search box ready for users to input their text.

      In the search.asp file the form is not named :-

      Code:
      Response.Write&#40;"<form method=""get"" action=""" & selfURL & """ class=""zoom_searchform"">"&#41; & VbCrlf
          Response.Write&#40;STR_FORM_SEARCHFOR & " <input type=""text"" name=""zoom_query"" size=""20"" value=""" & encQuery & """ class=""zoom_searchbox"" tabindex=""0"" />"&#41; & VbCrlf
      Any suggestions on how this could be achieved? I have viewed in IE, Netscape 6.1 and Firefox and get the same results with all.

      Comment


      • #4
        I thought I'd try adding the missing form name and apply David's solution to the search_template.html file and hey presto I now have the cursor blinking away in the search input box! (I remembered to use ZoomIndexer to make the change to the search.asp file)

        Code:
        Response.Write&#40;"<form method=""get"" name=""MySearchForm"" action=""" & selfURL & """ class=""zoom_searchform"">"&#41; & VbCrlf 
            Response.Write&#40;STR_FORM_SEARCHFOR & " <input type=""text"" name=""zoom_query"" size=""20"" value=""" & encQuery & """ class=""zoom_searchbox"" tabindex=""0"" />"&#41; & VbCrlf
        I hope this helps anyone else who has encountered a similar need.

        Comment


        • #5
          David's suggestion above was for search forms created by the user (in HTML).

          An alternative method that would not require a form name (and thus, not require editing the search script) would be the following:

          Code:
          <BODY onLoad="document.getElementById&#40;'zoom_query'&#41;.focus&#40;&#41;">
          For more information on using Javascript with forms, check out this page (also try a search on Google).
          --Ray
          Wrensoft Web Software
          Sydney, Australia
          Zoom Search Engine

          Comment


          • #6
            Ray

            Thank you for this line of code and the referral. I will look into converting to this method in the future.

            Comment

            Working...
            X