This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how do i restrict HTML tags in textarea

 
Jigar Naik
Ranch Hand
Posts: 762
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do i restrict HTML and other scripts tags in textbox or textarea ?

i mean user can write HTML and other tags like [html] abc [/html]
but in out put there should be no effect.

the effect should be like

System.out.println("mymethod1()");

o/p

mymethod1()
[ December 12, 2006: Message edited by: Jigar Naik ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look for HTML control characters (IE: <, >, &) and either escape them or reject the post and send the user an error message.
 
Jigar Naik
Ranch Hand
Posts: 762
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how do we go thru individual character of a textarea ???
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you retrieving the form fields now?
Post your the servlet or JSP code that you're using.
 
Jigar Naik
Ranch Hand
Posts: 762
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String s1 = req.getParameter("field_textarea");

I want to use java script but i m new to java script.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, this forum is for JSP (server side).

To do what I mentioned earlier, look at Java's String object.
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html
It has several methods for replacing characters and substrings.

Javascript is a client side technology (interpreted in the user's browser).
We have an HTML/Javascript forum where these technologies are discussed.
If you would like this thread to be move to that forum, let me know and I will move it for you.
 
Jigar Naik
Ranch Hand
Posts: 762
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes i want all that validation stuff to be done on client side and thats you i maintaned java script.

please move this topic to the right place.

thanks a lot.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You STILL have to do it on the server

onsubmit of the form you can do replace(/</gi,"<") and so on.

Eric
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic