Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

'&' missing while displaying Textbox values in JSP/jquery/javascript

 
S Nikam
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am getting some weired behaviour for below case.
Please help if anybody knows this issue.
I have jsp with texbox,I click next it will confirm the inputs on cofiramtion page and then submit.

In jsp when I enter any string with '&',its behaviour is as below.

abc & def --->abc & def
abc & def & -->abc & def
abc&def&ghi--> abc&def
abc&def&ghi & test-->abc&def&ghi & test

Means when I enter string with '&' without space the string/character after last '&' is
missing on the confirmation page.I am using jquery/javascript to display information on confirmation page.

Please help ..
Thanks!!
ssn
 
S Nikam
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got the solution for this

var name1 = document.getElementById(name).value;
name1 = name1.replace(/\&/g,'&');;
element1.innerHTML =name1

Thanks
ssn
 
Stefan Evans
Bartender
Posts: 1640
9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You do realise that & is a special character in HTML?

It should be encoded as & in any html.

The JSTL <c:out> tag will do that for you automagically.

& is also a special character in urls (used to seperate parameters). however if you are submitting a form, then that should be escaped automatically for you as well.
If you are building up the url string yourself, make sure you URLEncode any parameter values, which will escape the & characters.

Also note that to write &amp; on this forum you write it as &amp;amp;

 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic