Results 1 to 5 of 5

Thread: php and java script focus()

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Posts
    79

    php and java script focus()

    Hi all.
    I try to place focus in a textfield (Sup_no) after the page get an error message. I try coding it in Javascript along in php script.
    However, the code below does not function.
    I hope anyone here can help me correcting the code below.
    Thanks in advance.

    PHP Code:
        <?php
        $err 
    $_GET['msg'];
        if (
    $err=='error'){
            echo 
    "<br>";
            echo 
    "<center><font face=verdana size=2 color=red><b>Supplier No already existed in database, please key in new Supplier No</b><center>";
            echo 
    "<script language='JavaScript'>";
            echo 
    "document.form2.Sup_no.focus()";
            echo 
    "return false";
            echo 
    "</script>";
        }
         
    ?>

  2. #2
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: php and java script focus()

    Its hard to know whats going wrong without seeing all the code - would you be able to post more of the code (looks like a Javascript problem and not a PHP one).

    -- Ryan Jones
    My Blog.

    Ryan Jones.

  3. #3
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: php and java script focus()

    You cannot set focus while the document is loading.

    I suggest you learn how to write HTML and PHP properly before continuing however becuause that code is terrible.

    Have a look at this: http://www.vbforums.com/showpost.php...49&postcount=7
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Posts
    79

    Re: php and java script focus()

    Ok..thank you for the suggestion.
    I am just a beginner afterall.
    I need idea on how to set focus can be done in php script when the page is loading or is there some other way ?

  5. #5
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: php and java script focus()

    document.form2 is meaningless.

    To do any manipulation of the page you need to use the DOM functions. Any other method is non-standard and not guaranteed to work in more than one particular browser.

    Some suggestions: getElementById(), getElementsByTagName().

    Look Javascript functions up on MDC for excellent documentation.

Posting Permissions

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



Click Here to Expand Forum to Full Width