onblur/onfocus textarea default value entering into db php

I have seen this talked about but never answered. Maybe it has and I'm not sure where to find it.

I have several textareas and the onblur/onfocus are working great, but when the textarea is left empty, the "default value" is inserted into the database. How can I prevent that from happening?? I do not want "Add Public Notes Here!!" to be entered into the db.

    <td colspan="4"><textarea name="comments" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;">

Add Public Notes Here!!

Can anybody push me towards the right direction. Thanks!!


Well, you don't have the PHP code posted that inserts it into your database, so it's hard to tell you exactly what to do, but basically somewhere above that you will need to put a conditional that resets the value of the textarea submission if it contains the default string. Basically something like

<?php (isset($_POST['comments'] && $_POST['comments'] == 'Add Public Notes Here!!') {
    $comments = ''; } else { $comments = $_POST['comments']; } ?>

Of course, rather than $comments you need to use whatever variable contains the value that is getting inserted into your database. I can't help you much more unless you show more code.

You should check the default values on form submit event and empty the textareas have that

Need Your Help

tab object is undefined in chrome extension

javascript google-chrome-extension

I am adding a simple listener to a tab that shows the page action in a chrome extension, but each time, tab.id is undefined. This script runs in a background page:

Datatables default number of records to display

javascript php jquery datatable datatables

In dataTables I want to set an initial value to show in each page. How should I do this?