PDA

View Full Version : Apostrophe Issue



y1k2h3
11-07-2006, 07:51 AM
Anybody can help mi on this, { ' } thing.
It's will display an IE error box whenever I refreshes.
Pls help !!:confused:


<td class="RowGrey" height="19"><a href="#" onClick="displayOnForm(
'dog&#39;s&#39;');"> - </a> </td>

djr33
11-07-2006, 07:59 AM
onClick="displayOnForm(
'dog's'');"

That's likely the issue.
You should escape the single quotes you want displayed--
'dog\'s'

(What's the second single quote doing at the end of that?)

y1k2h3
11-07-2006, 09:17 AM
sorry to bother again.
The contents within displayOnForm() is generated during runtime.
So how can I change from { 'dog's'', } --> { 'dog\'s\'', } by using the function changeApostrophe()??
Example like for the attribute = lastName

Thanks once again.



function changeApostrophe(text){
var newString = "";
for (var i = 0; text.indexOf("'") >= 0; i++) {
var index = text.indexOf("'");
var firstHalf = text.substring(0, index);
newString = newString + firstHalf + "&#39;";
text = text.substring(firstHalf.length + 1, text.length);
}
newString += text;
return newString;
}


<td class="<cc:altColor/>" height="19"><a href="#" onClick="displayOnForm(
'<cc:corpItemAttribute attribute='rowNo'/>','<cc:corpItemAttribute attribute='salutationId'> - <cc:staticModelItemAttribute modelalias='cc.salutation'/></cc:corpItemAttribute>',
'<cc:corpItemAttribute attribute='industryId'> - <cc:staticModelItemAttribute modelalias='cc.industry'/></cc:corpItemAttribute>',
'<cc:corpItemAttribute attribute='lastName'/>',
'<cc:corpItemAttribute attribute='personnelId'> - <cc:staticModelItemAttribute modelalias='cc.personnel'/></cc:corpItemAttribute>',
'<cc:corpItemAttribute attribute='firstName'/>','<cc:corpItemAttribute attribute='middleName'/>',
'<cc:corpItemAttribute attribute='officeNo'/>','<cc:corpItemAttribute attribute='faxNo'/>',
'<cc:corpItemAttribute attribute='mobtelNo'/>','<cc:corpItemAttribute attribute='email'/>',
'<cc:corpItemAttribute attribute='homeNo'/>',
'<cc:corpItemAttribute attribute='createUserId'> - <cc:staticModelItemAttribute modelalias='cc.userid'/></cc:corpItemAttribute>',
'<cc:corpItemAttribute attribute='createDateTime'/>');">
<cc:corpItemAttribute attribute='firstName'/></a>
</td>

Twey
11-07-2006, 09:29 AM
str = str.replace(/'/g, "\\'");I don't think this is what you're looking for, though. I think you want to be able to pass in an apostrophe-delimited string value containing apostrophes, then convert it. You can't do this, since as soon as it's seen it'll throw a parse error.

What's this <cc:> namespace? I'm pretty sure that's not valid HTML. Is it parsed by the Javascript?

y1k2h3
11-07-2006, 09:44 AM
I using a jsp instead of a html. and the cc is a modified tag name. Nothing special about it. :p

Twey
11-07-2006, 10:07 AM
Ah, very well, so it'll be parsed into HTML by a server-side script.

Well, so long as the output doesn't contain any apostrophes, you should be fine. If it does, you'll have to replace them server-side.

y1k2h3
11-07-2006, 10:36 AM
No good, I'm only allow to code on the presentation tier not the business 1.
Below is the output from the server, still got the "Expected )" error from IE.
Oh God!!!! :(


<td class="RowGrey" height="19"><a href="#" onClick="displayOnForm(
'9',' - ',
' - ',
'dog&#39;s&#39;',
'P2 - PERSONNEL 2',
'dog&#39;s&#39;','dog&#39;s',
'123','',
'123','13@dfg.edfg',
'',
'junyong - Lee Jun Yong',
'11/07/2006 02:30:58 PM');">
- </a>
</td>

<td class="RowGrey" height="19"><a href="#" onClick="displayOnForm(
'9',' - ',
' - ',
'dog&#39;s&#39;',
'P2 - PERSONNEL 2',
'dog&#39;s&#39;','dog&#39;s',
'123','',
'123','13@dfg.edfg',
'',
'junyong - Lee Jun Yong',
'11/07/2006 02:30:58 PM');">
dog&#39;s&#39;</a>
</td>

Twey
11-07-2006, 01:43 PM
There are still apostrophes there. There's one alternative left, but it's quite ugly:
<td class="<cc:altColor/>" height="19"><a href="#" onClick="displayOnForm(
&quot;<cc:corpItemAttribute attribute='rowNo'/>&quot;,&quot;<cc:corpItemAttribute attribute='salutationId'> - <cc:staticModelItemAttribute modelalias='cc.salutation'/></cc:corpItemAttribute>&quot;,
&quot;<cc:corpItemAttribute attribute='industryId'> - <cc:staticModelItemAttribute modelalias='cc.industry'/></cc:corpItemAttribute>&quot;,
&quot;<cc:corpItemAttribute attribute='lastName'/>&quot;,
&quot;<cc:corpItemAttribute attribute='personnelId'> - <cc:staticModelItemAttribute modelalias='cc.personnel'/></cc:corpItemAttribute>&quot;,
&quot;<cc:corpItemAttribute attribute='firstName'/>&quot;,&quot;<cc:corpItemAttribute attribute='middleName'/>&quot;,
'<cc:corpItemAttribute attribute='officeNo'/>&quot;,&quot;<cc:corpItemAttribute attribute='faxNo'/>&quot;,
&quot;<cc:corpItemAttribute attribute='mobtelNo'/>&quot;,&quot;<cc:corpItemAttribute attribute='email'/>&quot;,
&quot;<cc:corpItemAttribute attribute='homeNo'/>&quot;,
&quot;<cc:corpItemAttribute attribute='createUserId'> - <cc:staticModelItemAttribute modelalias='cc.userid'/></cc:corpItemAttribute>&quot;,
&quot;<cc:corpItemAttribute attribute='createDateTime'/>&quot;);">
<cc:corpItemAttribute attribute='firstName'/></a>
</td>

y1k2h3
11-09-2006, 08:48 AM
I encounter javascript error when the a single input contains both quote and apostrophe. I tried to escape it using \" and &.#.3.9;for apostrophe &.q.u.o.t.;for quote. But no luck!!!

:confused:



<input type='hidden' name='rowNoItemAttr' value=\"2 \">
<input type='hidden' name='salutationIdItemAttr' value=\"6 - ARCH"S \">
<input type='hidden' name='industryIdItemAttr' value=\" - "\>
<input type='hidden' name='lastNameItemAttr' value=\"Las't Name&quot; \">
<input type='hidden' name='personnelIdItemAttr' value=\"P2 - PERSONNEL 2 \">
<input type='hidden' name='firstNameItemAttr' value=\"Firs't Nam&quot;e \">
<input type='hidden' name='middleNameItemAttr' value=\"Mi'ddle Nam&quot;e \">
<input type='hidden' name='officeNoItemAttr' value=\"2123 \">

y1k2h3
11-09-2006, 10:02 AM
sorry guys, my mistake. I found the answer to my question. :D