PDA

Click to See Complete Forum and Search --> : php and java script focus()


Rina
Jul 17th, 2006, 04:16 AM
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
$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>";
}
?>

sciguyryan
Jul 17th, 2006, 04:54 AM
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

visualAd
Jul 17th, 2006, 05:02 AM
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?p=2440249&postcount=7

Rina
Jul 17th, 2006, 06:53 AM
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 ?

penagate
Jul 18th, 2006, 11:50 PM
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 (http://developer.mozilla.org/) for excellent documentation.