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.
Who is Participating?
Pawel WitkowskiConnect With a Mentor Senior Javascript DeveloperCommented:
3. On server side:,"UTF8");

after this do Regular Expression that will replace all "   to  \"    - this is breaking out outside a bracers, rest should be fine
David S.Commented:
Replace each double-quote character with "&quot;"
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?
7 new features that'll make your work life better

It’s our mission to create a product that solves the huge challenges you face at work every day. In case you missed it, here are 7 delightful things we've added recently to monday to make it even more awesome.

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?
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..
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 ="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");,"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..
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

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%>);
rupvisAuthor Commented:
thank you so much... will try out and let you know.
rupvisAuthor Commented:
using your solution now ..thanks wilq32
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.