Welcome to WebmasterWorld Guest from 54.147.50.227

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

controling focus with php

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

Junior Member

10+ Year Member

joined:Jan 4, 2006
posts:85
votes: 0


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 July 17, 2007 (gmt 0)

Preferred Member

10+ Year Member

joined:Nov 25, 2005
posts:392
votes: 0


You can control focus thru html "z-index"
6:29 am on July 17, 2007 (gmt 0)

Junior Member

10+ Year Member

joined:Jan 4, 2006
posts:85
votes: 0


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 July 17, 2007 (gmt 0)

Full Member

5+ Year Member

joined:July 13, 2007
posts:235
votes: 0


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">
document.getElementById('myElementId').focus();
</script>

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 July 18, 2007 (gmt 0)

Junior Member

10+ Year Member

joined:Jan 4, 2006
posts:85
votes: 0


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.