Forum Moderators: coopster

Message Too Old, No Replies

auto insert test into text area and focus cursor

         

bilenkyj

10:34 am on May 2, 2008 (gmt 0)

10+ Year Member



Hi Guys im looking to do the following but am unsure how to start.

I have a text area - notes which reads and writes to database when form is submitted. There is only one record in the database so it looks like this

entry

new entry

future entry

its up to the user to add new lines and add in dates if needed - one save updates the previous saves so you always have the old text on display. (hope this makes sense)

anyways because its set like this its difficult to add in time stamps for each entry (i have a last updated date but thats all) like i said the user would need to add in the date of each entry manually.

What i would like is when the form is displayed to the user - all the previous submitted text is show but a new line is added to the end of file and inserts a date then the user can start typing

now is this possible at all - i have s simple text insert script using javascript so when the user click on a link it inserts a pre defined text into the text area - problem is it over writes anything in there, not good.

PHP_Chimp

12:54 pm on May 2, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




// get info from database
echo '<textarea>';
echo $database_info['textarea']."\n";
echo [url=http://uk.php.net/manual/en/function.date.php]date[/url](/* you choose format */)."\n";
echo '</textarea>';

Just add your break and date to the text that is in the text area already.
Alternatively you could just add the new comments onto the end of the text in the database. For this you may not need to load the text that is already stored.

bilenkyj

1:20 pm on May 2, 2008 (gmt 0)

10+ Year Member



thanks php chimp, that was simple in the end! but one more thing - i need it to focus cursor just after the date?

bilenkyj

3:01 pm on May 2, 2008 (gmt 0)

10+ Year Member



<TEXTAREA NAME="notes" COLS=80 ROWS=30 ondblclick="setCursorPos(this);">

<script type="text/javascript">

function setCursorPos( x ) {

var txtRange = x.createTextRange();
txtRange.moveStart( "character", x.value.length - 0 );
txtRange.moveEnd( "character", 0 );
txtRange.select();
}

</script>

thanks for your help