maybe you do may try this:
1. regsub -all -- {'} $name {\'} name
2. ns_quotehtml $name
The regsub helps to not break the js single quotes, the quotehtml is for the outer html tags and quotes.