954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

getting mouse focus without onload

i need help in my project,
i need to get the mous focus on the username text field in the admin page
but the problem is the body & head of the page is in another page
so when i use onload="focus();" and get the element by id e cant see it

is their any other way to get mouse focus without using the onload method???

yasmena
Light Poster
45 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 
i need help in my project, i need to get the mous focus on the username text field in the admin page but the problem is the body & head of the page is in another page so when i use onload="focus();" and get the element by id e cant see it is their any other way to get mouse focus without using the onload method???


You mean like frames?

R0bb0b
Posting Shark
998 posts since Jun 2008
Reputation Points: 358
Solved Threads: 89
 

what do u mean by frames ??
i mean i have the and tags in a script called X.php and the body of this script includes a script called (admin.php) this admin.php is the one containing my text field i want to get focus ON. that's what i mean

yasmena
Light Poster
45 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 
what do u mean by frames ?? i mean i have the and tags in a script called X.php and the body of this script includes a script called (admin.php) this admin.php is the one containing my text field i want to get focus ON. that's what i mean


That should work just fine. Post your scripts.

R0bb0b
Posting Shark
998 posts since Jun 2008
Reputation Points: 358
Solved Threads: 89
 

If I am understanding you correctly, the following should work:
In the script containing the add something like this inside the tags:

<?
$currentFile = $_SERVER["SCRIPT_NAME"];
$parts = Explode('/', $currentFile);
$currentFile = $parts[count($parts) - 1];

if($currentFile == 'admin.php') {
  //put JS code here
}
?>


This will mean that the JavaScript code will only be loaded with the admin.php script and you can then use the onload function.

Will Gresham
Master Poster
755 posts since May 2008
Reputation Points: 96
Solved Threads: 125
 
<?
$currentFile = $_SERVER["SCRIPT_NAME"];
$parts = Explode('/', $currentFile);
$currentFile = $parts[count($parts) - 1];

if($currentFile == 'admin.php') {
  //put JS code here
}
?>

Instead we can use simply:

$currentFile=basename($_SERVER['PHP_SELF']);
Shanti C
Posting Virtuoso
1,642 posts since Jul 2008
Reputation Points: 137
Solved Threads: 162
 

Instead we can use simply:

$currentFile=basename($_SERVER['PHP_SELF']);

That would be the better way, yes. Forgot about that one :)

Will Gresham
Master Poster
755 posts since May 2008
Reputation Points: 96
Solved Threads: 125
 

U know i tried what u said but nothing happens ??
i want to ask sth.
does the admin.php script needs 2 be in the same directory as the script X.php ..
and i also copied it to the same directory but nothing happens

yasmena
Light Poster
45 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 
U know i tried what u said but nothing happens ?? i want to ask sth. does the admin.php script needs 2 be in the same directory as the script X.php .. and i also copied it to the same directory but nothing happens


It doesn't matter, it's all html when it come out anyway. I can include 100 php files from any directory I want and the javascript dom has access to the whole page. Again, post your scripts.

R0bb0b
Posting Shark
998 posts since Jun 2008
Reputation Points: 358
Solved Threads: 89
 

<? ob_start();?>
<?session_start() ;

include("include/connection.php") ;

?>

Untitled

<?

$currentFile= basename($_SERVER['PHP_SELF']);
$parts = Explode('/', $currentFile);
$currentFile = $parts[count($parts) - 1];
if($currentFile == 'login.php')
{
echo " ";

}


?>



homesearchhelp



<?

if($_SESSION['utype']=='admin')

{

?>

welcome <? echo $_SESSION['uName'] ;?>Log out

<? include("admin/includes/links.php") ;?>

<? include("admin/includes/adminlinks.php") ;?>

<?

}

else

{

include("login.php") ;

}

?>


.....
the LOGIN.PHP (or ADMIN.PHP)
<?

if($_GET['mode']=='')

{

?>

<?

if($_GET['log']=='fail')

{

?>

Sorry this username or password must be wrong

<?

}

?>

Username

Password


<?

}

else if($_GET['mode']=='submit')

{

$UserName = $_POST['UserName'];

$Password = $_POST['Password'];

$encPassword=md5($Password);

$sql="SELECT * FROM admin where username='$UserName' and password='$encPassword' " ;

$result=mysql_query($sql);

if($array=mysql_fetch_array($result))

{

$_SESSION['uName']=$array[1];

$_SESSION['uID']=$array[0] ;

$_SESSION['utype']='admin' ;

?>

<?

}

else

{

?>

<?

}

}

?>

yasmena
Light Poster
45 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 

You have two lines that look like this:
document.form1.getElementById('1').focus();

Once I changed it to: document.getElementById('1').focus();

It worked fine.

R0bb0b
Posting Shark
998 posts since Jun 2008
Reputation Points: 358
Solved Threads: 89
 

Im So Glad It Works With You :)
But i dont know why its not working with mee
inaddition to that
at the bottom there is a message that says "Error On Page"

yasmena
Light Poster
45 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 

Open up the error console of firefox, clear the errors out of it, do a test run of your application and tell me what the errors are.

R0bb0b
Posting Shark
998 posts since Jun 2008
Reputation Points: 358
Solved Threads: 89
 

Excuse Me But im not using FireFox im using Opera and IE7 ..
and i dont know how to open the error console

yasmena
Light Poster
45 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 

I don't know about opera since I do most of my debugging in firefox and ie, but the error console in firefox is under the tools -> error console. It is very helpful when debugging javascript.

R0bb0b
Posting Shark
998 posts since Jun 2008
Reputation Points: 358
Solved Threads: 89
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You