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!

Including # in a string 3

Status
Not open for further replies.

Fingerprint

Programmer
Oct 21, 2002
35
GB
Hi,

hope someone can help because this is a pain in the bum!

I have written some code as part of a validation routine which automatically determines which anchor tag to go to depending on the name of the field that was validated.

The problem is that I keep getting an invalid character message when I run the code, and can't work out how to include the ASCII code for # instead (35).

Here's the code I'm using. constructor is just a string slicer that cuts the original field name down to it's stem, and tst is the form element id picked up from a for loop.
Constructor returns 'str1'.

Code:
constructor(tst);
str2 = eval(str1 + "yn");
alert ('Please check either "Yes" or "No" for this question');
str3 = str1.slice(5);
str3 = String("document.location = #" + str3);
eval(str3);

Does anybody have any ideas?

Thanks guys,

fingerprint

a posse ad esse
 
try using the escape sequence str3 = String("document.location = \#" + str3);
 
I have given up and moved to focusing on a different linked element
:(
Oh well...


Thanks for trying newbiepg!

fingerprint


a posse ad esse
 
str3 = String("document.location = '#'" + str3);

=========================================================
while (!succeed) try();
-jeff
 
I'd replace these two lines :

str3 = String("document.location = #" + str3);
eval(str3);

with :

document.location = "'#" + str3 + "'"

Gary Haran
==========================
 
Use UNICODE! unicode equivalent for # is \u0023

Hence<snip>:-

str3 = String(&quot;document.location = \u0023&quot; + str3);

 
Thanks guys! Guess I should have been a little more patient huh?

Stars all round!


fingerprint

a posse ad esse
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top