Pass String With Spaces Into Javascript
i'm trying to pass a php defined string with spaces to a javascript function, so that i can append to a query string. However, the function only works when there are NO spaces, an
Solution 1:
The problem is you didn't quote the attribute value. You can leave quotes off of attribute values only if the value doesn't contain spaces, otherwise the HTML processor can't tell when an attribute ends. Even so, it's not recommended; you should always quote HTML attributes.
<ahref="showUser('<?phpecho addslashes($username) ?>')">user</a>
should work. The call to addslashes
escapes quotes, which would otherwise cause another problem (ending the attribute or string argument of showUser
too soon).
Solution 2:
Yes you can you are missing " in you xml attribute field: Each attribute must have a starting and an ending "
myField=
"blabla ...
"
onClick="showUser(escape('<?phpecho$deptname; ?>'))"
Solution 3:
Try the Unicode escape sequence for a space character, '\u0020'.
Post a Comment for "Pass String With Spaces Into Javascript"