Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Storting an Apostrophy

Status
Not open for further replies.

egolds

MIS
Aug 29, 2001
105
US
I have a field where a user enters data and I store this value in a session variable. On the originating page I have the session variable as the source for the field:
value = <%=&quot;'&quot;&Session(&quot;PastCoName1&quot;)&&quot;'&quot;%>

The single quote solved the problem with spaces but my problem is now with apostrophies. If someone enters a name with an apostrophy into the original field, the value with the apostrophy will store into the session variable but does not place back into the field, I get everything up to the apostrophy. Unfortunately I do not have the option of disallowing apostrophies since this is a compnay name field.

Thanks in advance

Eric
 
egolds,

You do not have to use <%= and %> while in scripting context.

value = Session(&quot;PastCoName1&quot;)

If you want your text enclosed in single quotes, then:

value = &quot;'&quot; & Session(&quot;PastCoName1&quot;) & &quot;'&quot;



fengshui_1998
 
Eric,

You need to double up the apostrophes in the string and then they will be encoded properly. Try the following:

value = <%= &quot;'&quot; & Replace(Session(&quot;PastCoName1&quot;), &quot;'&quot;, &quot;''&quot;) & &quot;'&quot; %>

Alternatively you could do this when storing the session variable:

Session(&quot;PastCoName1&quot;) = Replace(value, &quot;'&quot;, &quot;''&quot;)

Hope this helps :)

Regards,

Ben
 
I tried adding the double quote in both places (not at the same time). Neither worked. It worked as far as the replace command working but not once it was in the text field. I even tried hard coding some text with double apostrophes in the field which did not work. Could this be an IE vs. Netscape issue? This is an in-house app so I would prefer to keep it an IE app.
 
eric,

If you have a value in a web page that has a single quote and you are using ASP, try this. The value must be enclosed in quotes or else it will chop off the rest of the string.

<html>
<body>
<%
xval = &quot;o 'connell&quot;
Session(&quot;test&quot;) = xval
%>
<input type=&quot;text&quot; value= &quot;<%=Session(&quot;test&quot;)%>&quot;>
</body>
</html>


fengshui_1998
 
eric,

Sorry, you need the form tag for NS.

<html>
<body>
<%
xval = &quot;o 'connell&quot;
Session(&quot;test&quot;) = xval

%>
<form name=&quot;frm1&quot;>
<input type=&quot;text&quot; value= &quot;<%=Session(&quot;test&quot;)%>&quot;>
</form>
</body>
</html>

fengshui_1998
 
Putting the double quotes outside the script is what i needed. Didn't even need to use the replace once I did that.

Thanks for the help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top