Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

controling focus with php



9:58 pm on Jul 16, 2007 (gmt 0)

5+ Year Member

Are there ways to control focus in a .php page withing a php script? I can't find anything in the documentation. I've also tried using JavaScript along with php but that doesn't seem to work.


5:21 am on Jul 17, 2007 (gmt 0)

10+ Year Member

You can control focus thru html "z-index"


6:29 am on Jul 17, 2007 (gmt 0)

5+ Year Member

What I mean if a method or event similar to JavaScript's focus() ability. When my php pages refresh, nothing is 'onfocus'


2:21 pm on Jul 17, 2007 (gmt 0)

5+ Year Member

There's no way of setting focus without javascript, to my knowledge. However, you could have your PHP page echo this near the </body> tag...

<script type="text/javascript">

However, this sort of code must come AFTER "myElementId" on the page (thus why I recommend putting it just before the </body> tag), because otherwise the javascript will load and execute, but will not find "myElementId" because it hasn't been loaded yet.

Alternately, you could find a method of determining when the page has loaded and call a function to focus on the element.

If you use Firefox, I would highly recommend downloading a plugin (not sure if I can name it here) that allows you to debug javascript. If any javascript errors come up, it will show you what the error is and where in the code it comes from--you can also set breakpoints in the JS code and step through it to see where your problem occurs and what the values of nearby variables are. Very handy.

Hope this helps!


6:40 am on Jul 18, 2007 (gmt 0)

5+ Year Member

Yeah WesleyC, I think that is the way to do it. I guess I'll use JavaScript to check everything then use php for handling the info.

Featured Threads

Hot Threads This Week

Hot Threads This Month