can't display quoted text in input box

I am trying to load data from database into an input box. Now this data after being read from the database is decoded. I can print the value correctly on html but somehow when the variable is applied to the input box it would not show. This is because the value contains quoted characters. What changes would i need to get the data displayed.
Sample code:
<td NOWRAP>Select Y1:<input type='text' name='<portlet:namespace />sql_query1' value="<%=sql_query1%>"  size="10">

when <%=sql_query1%> is printed on html page it shows up fine but would not display in the input box.
LVL 2
rupvisAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David S.Commented:
Replace each double-quote character with "&quot;"
0
rupvisAuthor Commented:
that would mean manually editing the string. This is the basic reason why i have decoded the text.. Is there no way i can have the text displayed  without having to modify every special character?
0
David S.Commented:
Why would you have to manually edit it?  Why couldn't you write a statement in whichever server-side language you are using to automatically replace those chracters?
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

rupvisAuthor Commented:
Yes that is what i meant .. if i replace characters would i not need to replace all special characters? Is there a more generic approach to the issue?
For instance we URLEncode strings to avoid these issues and then decode on server side. My only problem is getting the text displayed on the input box..
Thank you for your attention into the matter..
0
rupvisAuthor Commented:
All this code comes within a portlet deployed under liferay..
I encode the string before saving it in the database using:
   sql_query1 = java.net.URLEncoder.encode(request.getParameter("sql_query1"));
          prefs.setValue("SQL_QUERY1", sql_query1);

When the user needs to edit entered values i retrieve the data and decode it using
  String sql_query1 = prefs.getValue("SQL_QUERY1", "Column1");
      sql_query1=java.net.URLDecoder.decode(sql_query1,"UTF8");

now <%=sql_query1%> has the decoded value which is a string eg "id" with quotes. This data does not show up when applied to the input box
Select Y1:<input type='text' name='<portlet:namespace />sql_query1' value="<%=sql_query1%>"  size="10">

i tried printing sql_query1 on the html page and it shows the data fine.. so why not in the text box...
Again i need a generic technique of handling this issue..
0
Pawel WitkowskiSenior Javascript DeveloperCommented:
Well problem is really not trival hmm... I can propose you at least 2 solutions:

1. Use a <textarea> </textarea>  and put decoded conent there (simple solution).

2. (more complex). Instead of decoding on server side, pass this value to javascript and decode it on client side using one of those:

decodeURI   or
decodeURIComponent

like this:

<td NOWRAP>Select Y1:<input id='idY1' type='text' name='<portlet:namespace />sql_query1' value=""  size="10">

<script type="text/javascript">
   document.getElementById('idY1').value = decodeURIComponent(<%=sql_query1%>);
</script>
0
Pawel WitkowskiSenior Javascript DeveloperCommented:
3. On server side:

      sql_query1=java.net.URLDecoder.decode(sql_query1,"UTF8");


after this do Regular Expression that will replace all "   to  \"    - this is breaking out outside a bracers, rest should be fine
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rupvisAuthor Commented:
thank you so much... will try out and let you know.
Cheers
0
rupvisAuthor Commented:
using your solution now ..thanks wilq32
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Development

From novice to tech pro — start learning today.