Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6201435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:33:13+00:00 2026-05-24T04:33:13+00:00

I have a text area which I need to prevent from having javascript entered.

  • 0

I have a text area which I need to prevent from having javascript entered. If they enter text. And then say some javascript, The javascript runs. And the text does not get entered.

I guess is there a way to stop javascript from being entered in the textfield(say a regex in validation.xml? ) or is there something else I can do from preventing the javascript from being ran at all(maybe on the jsp)!

Here’s what I got:

JSP:

   <td>
         You have <strong><span id="commentsCounter">${const['COMMENT_MAX_LENGTH'] - fn:length(commentForm.comment)}</span></strong> characters left.<br/>
            <textarea id="comment" name="comment" rows="2" cols="125" style="width:640px;"
                 onkeypress="characterCounter('commentsCounter',${const['COMMENT_MAX_LENGTH']}, this)"
                 onkeydown="characterCounter('commentsCounter',${const['COMMENT_MAX_LENGTH']}, this)"
                 onkeyup="characterCounter('commentsCounter',${const['COMMENT_MAX_LENGTH']}, this)"></textarea>

                    <a href="javascript:addComment();"><img src="../images/icon_add.gif" border="0" alt="Add"/></a>
        </td>

here is my validation.xml:

<form name="whatif_add_entry_comment">
    <field property="id" depends="minlength">
        <msg name="minlength" key="ID has a minimum length of {0}" resource="false" />
        <arg name="minlength" key="${var:minlength}" resource="false" />
        <var>
           <var-name>minlength</var-name>
           <var-value>0</var-value>
        </var>
     </field>
     <field property="comment" depends="required,minlength,maxlength">
        <msg name="required" key="Comment name is required." resource="false" />
        <msg name="minlength" key="Comment has minimum length of {0}" resource="false" />
        <arg name="minlength" key="${var:minlength}" resource="false" />
        <var>
           <var-name>minlength</var-name>
           <var-value>1</var-value>
        </var>
        <msg name="maxlength" key="Comment has a maximum length of {0}" resource="false" />
        <arg name="maxlength" key="${var:maxlength}" resource="false" />
        <var>
           <var-name>maxlength</var-name>
           <var-value>250</var-value>
        </var>
     </field>
    </form>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T04:33:16+00:00Added an answer on May 24, 2026 at 4:33 am

    You don’t need to (and can’t easily) escape the javascript itself. You need to escape the HTML. The easiest way is through commons-lang StringEscapeUtils.escapeHtml(..) (prefer version 3.0)

    If you need to retain other html tags, it would be much harder to escape only the javascript. You’d have to look for onclick, onmouseover, etc, etc. For that – take a look at JSoup Cleaner.

    If you at all need to support some markup formatting, the usual practice is to allow some limited subset of html or custom tags, like Markdown or BBCode.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text area which is filled from database. In that textarea comma's
need help from some gurus here, I have a database which I have moved
I have a page which has a rectangular area with text and icons in
I have a form with a textarea. Users enter a block of text which
I have a text-area where text and an image url is entered. Text is
I have some text area field in my grails application. I got the following
I have a textarea which is a tinymce editor. This text area contains html.
I have a system which allows users to enter HTML-reserved characters into a text
I need to hide some text (Add £0.20) which is within a td. I
I have several textfields which will populate a text area. I managed to populate

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.