Jump to content

help with focus() please....


meomike2000

Recommended Posts

i have a simple message system and i use focus to set the location of the cursor to the correct box when the page loads... my problem is when i click on reply and the page loads, the focus is on the correct box,,, but that box has the original message information displayed and that is the box that i want the focus to be on,,, just it is at the bottom of the box after the original message,,,, can somebody help me get this to the top. i know very little about js ...

 

this is what i got. also the page is php.

 

echo '<script type="text/javascript">
function setFocus()
{
     document.getElementById("message").focus();
}
</script>';

 

and i use this to get the original message in the box.

 

//set message display in box.
$test = "\n\n\n\n...............!!original message!!...............\n\n".$row[1]." wrote:\n\n".$row[3];

 

and this is the box.

 

<textarea rows="10" cols="50" wrap=hard id="message" name="message" onload=setFocus()>';
echo $test;
echo '</textarea><br>

 

any help would be great...

 

thanks mike......

Link to comment
https://forums.phpfreaks.com/topic/148829-help-with-focus-please/
Share on other sites

i have tried it that way and i get the same result.

 

the focus is on the box, but i use information from another form to be the default message for the box.

 

the cursor is after this default text... i want it at the top of the input box and not after that....

 

that is the only problem i have.. i  know very little about js like i said.

 

you said to onload=setFocus() outside of html..  is this correct for that....

 

echo '<title>' . $title . '</title>';

echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"

"http://www.w3.org/TR/html4/strict.dtd">';

echo 'onload=setFocus()';

echo '<body>';

 

thanks mike...

that works, but still the same thing cursor after the message..

 

the problem could be something else not sure...

 

what i am trying to accomplish is a simple message system, you can send and receive messages fine, now i have attempted to add a reply so that u can reply to a message.

 

this reply button sends some message identification information to a php script that gets the username that sent the message. the original subject and message.

 

all is in the correct spot on the form and i have added and re: to the subject and that works fine.

 

in the message area is the problem.

 

i want to be able to give some area at the top of the textarea for the new message but still show the original message below that.  and i want the focus to be on that box and be at the top......

 

hope that makes sense.....

 

mike.....

you have to have a username and password to get to it.....

 

will this help:

 

//used to set where cursor will be on page load.
echo '<script type="text/javascript">
function setFocus()
{
      document.getElementById("message");
      message.focus();
}
onload = setFocus;
</script>';

//includes. 
include '../login/dirconf.php';

//open connection to database server.
$connection = mysql_connect($host, $user, $pass) or die ('unable to connect!');

//select  database to use.
mysql_select_db($db) or die ('unable to select database!');

$query = "select fr_uid, fruser, sub, mess from messages where touid = '" . $userid . "' and mid = '".$mid."'";
$result = mysql_query($query) or die ('error getting page info:' . mysql.error());

$row = mysql_fetch_row($result);

//set message display in box.
$test = "\n\n\n\n...............!!original message!!...............\n\n".$row[1]." wrote:\n\n".$row[3];

//finish page header here.
echo '<title>' . $title . '</title>';
echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
	"http://www.w3.org/TR/html4/strict.dtd">';

echo '<body>';

$error = $_SESSION['error'];
$error_string = $error; 
$userid;
echo 	$error_string. '<br >
<form method="post" action="send_mess.php?userid=' .$userid. '">reply to message # '.$mid.'<br>

        To:   <input type="text" name="to" size="30" value="'.$row[1].'"><br>
<br>
Subject:   <input type="text" name="subj" size="30" value="RE: '.$row[2].'"><br>
<br>
<textarea rows="10" cols="50" wrap=hard id="message" name="message">';
echo $test;
echo '</textarea><br>
<br>
<input type="submit" name"submess" value="send">     <input type="button" name="cancel" style="width:90px;" value="cancel" onClick="window.location=\'message?userid=' . $userid . '\'"><br>
</form>';


unset ($_SESSION['error']);

echo '</body>';

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.