rupvis
asked on
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.
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.
Replace each double-quote character with """
ASKER
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?
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?
ASKER
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..
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..
ASKER
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.g etParamete r("sql_que ry1"));
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.URLDec oder.decod e(sql_quer y1,"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..
I encode the string before saving it in the database using:
sql_query1 = java.net.URLEncoder.encode
prefs.setValue("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
sql_query1=java.net.URLDec
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..
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('i dY1').valu e = decodeURIComponent(<%=sql_ query1%>);
</script>
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('i
</script>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thank you so much... will try out and let you know.
Cheers
Cheers
ASKER
using your solution now ..thanks wilq32