SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    USA
    Posts
    1,407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    body tag in template header - how to use focus() on SOME forms?

    I use a template header that includes the body tag. The header is on all pages. One page is the login form and on that form I want to give focus() to the user id field when the page is opened. the login form and fields are not part of the header file but the content.php file/page.

    How can I write a script that knows which page is being loaded and IF it's the login form, give focus() to the user field?

    I am using php in these forms so, if it's easier to do it with php, let me know.

    Thanks.

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You could include the javascript for it only if it's the login page. Something like this:
    PHP Code:
    <?php
    if (basename($_SERVER['SCRIPT_FILENAME']) === 'login.php') { ?>
    <script type="text/javascript">
    window.onload = function() {
      document.getElementById('userid').focus();
    }
    </script>
    <?php ?>

  3. #3
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    USA
    Posts
    1,407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    beautiful - I love the simplest solution - many many thanks man!


Bookmarks

Posting Permissions

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