Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
127
rated 0 times [  133] [ 6]  / answers: 1 / hits: 17427  / 12 Years ago, wed, january 9, 2013, 12:00:00

My hypertlink generated by JavaScript is as follows:




'<a href=# onClick=passSearchTerm(' +aa + ');>View</a>' 



The parameter passes wells when the string is as follows:




var aa = 'TAGS(\ab\)'; 



I confirmed it by alerting inside the function




function passSearchTerm(aa)
{
alert(aa);
}




However, this wont alert when the var is defined as follows:




var aa = 'TAGS(a b)'; //space between a and b




Can anyone suggest me how to pass such string? Thanks in advance for your help.
Actually I am trying to pass likely following string:




TAGS(a or b)



More From » html

 Answers
20

While generating ur hyperlink by javascript use encodeURIComponent
ex.



<a href=# onclick=passSearchTerm(' + encodeURIComponent(aa) + ')>View</a>


and while retriving use decodeURIComponent



function passSearchTerm(aa) { alert(decodeURIComponent(aa)); }

[#80985] Tuesday, January 8, 2013, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
victorr

Total Points: 193
Total Questions: 86
Total Answers: 105

Location: Pitcairn Islands
Member since Thu, Jun 24, 2021
3 Years ago
victorr questions
Fri, Nov 13, 20, 00:00, 4 Years ago
Sat, Jul 25, 20, 00:00, 4 Years ago
Thu, Jun 11, 20, 00:00, 4 Years ago
;