Categories:

Home / Free JavaScripts / Forms / Here

Cut & Paste Strip HTML Tags (form) script

Credit: JavaScript Kit

Description: This script removes any HTML tags from user entered data such as a TEXTAREA before the form is submitted. This is generally a good idea, as HTML tags can corrupt the rest of your form contents or even pose a security risk.

See also: HTML to Entities (form) script

Example:


Directions: Simply add the below script into the <BODY> section of your page:

To demonstrate how to use this script with the desired form elements, lets use the sample form included in the code:

<form onSubmit="stripHTML(this.data1, this.data2)">
<textarea name="data1" style="width: 400px; height: 100px"></textarea><br />
<textarea name="data2" style="width: 400px; height: 100px"></textarea><br />
<input type="submit" value="submit">
</form>

The part in red is what you'll need to add to your form. "this.data1" and "this.data2" corresponds to the names of the form elements you want any HTML tags to be removed onsubmit. You can enter as many form elements as you wish- simply separate each one with a comma.

Now, you're free to call "stripHTML()" differently, such as via the event handler "onBlur" to strip any HTML tags as soon the user removes the focus from the form element in question.


Copyright 1997-2007 JavaScript Kit. NO PART may be reproduced without author's permission.