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>";
}
?>
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
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
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 ?
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.