Very Basic Javascript Validation

Hi,

I have a textarea on a page, and I want to implement some simply validation, just to check that it’s not empty. If the user presses the submit button and the textarea is empty, I have a popup that I want to be displayed.

Here’s the form code:

HTML Code:

<form name="addData" method="post" action="addData.php">
<textarea name="data" cols="60" rows="10"></textarea>
<br />

<input type="submit" value="Submit">
</form>


Here’s the popup code that I would like to be displayed if the textarea is empty:

HTML Code:

<div id=popup>
        <p>Look's like you forgot to leave a message! <a href=# class=hide>Hide</a> </p>
</div>


I’ve tried so many tutorials and examples online, but none of them will work at all – whether I use an onClick on the Submit button, or an onSubmit on the form.

Any help to solve this would be greatly appreciated.

This entry was posted in answer. Bookmark the permalink.

Leave a Reply