Uncaught SyntaxError: Unexpected token ILLEGAL [Resolved]

Posted by Vuyiswamb under jQuery on 10/20/2011 | Points: 10 | Views : 10355 | Status : [Member] [MVP] [Administrator] | Replies : 7
Good Day All

in my page i have a hyperlink button in a gridview defined like this


       <a href="#" onclick="<%#  String.Format("return showComment('{0}','{1}')", Replace(Eval("Field1").ToString(),Chr(13),"<BR>"), Replace(Eval("Field2").ToString(),Chr(13),"<BR>") ) %>">

<img src="../../Imgs/comment2.png" />
</a>


and the Function showComment is defined like this




function showComment(CommentPend,CommentCancel)
{
$("#btnclose").unbind();
$("#divPendComment").center();
$("#divPendComment").fadeIn('slow');

$("#txtcomment").val(CommentPend.toString().replace(/^[a-z0-9 ]$/i, ''));

$("#txtcommentCancel").val(CommentCancel.toString().replace(/^[a-z0-9 ]$/i, ''));

$("#btnclose").click(function (e)
{

$("#divPendComment").fadeOut('slow');
e.preventDefault();

});
return false;
}


now as you can see i am trying to get rid of the special characters like the carriage returns but still i get a a javascript error when this link is clicked

Uncaught SyntaxError: Unexpected token ILLEGAL

thanks

Thank you for posting at Dotnetfunda
[Administrator]



Responses

Posted by: Vuyiswamb on: 10/20/2011 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down

Resolved
It took longer than expected. so because of time as the data was coming from the DB , i had to clean it from there.

This issue has been resolved.

Thanks

Thank you for posting at Dotnetfunda
[Administrator]

Vuyiswamb, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: SheoNarayan on: 10/20/2011 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
Hi Vuyiswa,

What is the value you are getting onclick event of the button, is there still some special characters? Go to the source of the page and copy-paste the onclick event value that should give some clue on what is going on.

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Vuyiswamb, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 10/20/2011 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
This is what the html show me


 <a href="#" onclick="return showComment('This is another<BR>

with a carriage return<BR>
and a differentone<BR>
','This<BR>
is the <BR>
<BR>
reason that i did this>> ')">

<img src="../../Imgs/comment2.png" />
</a>


Thank you for posting at Dotnetfunda
[Administrator]

Vuyiswamb, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ndebata on: 10/20/2011 [Member] Starter | Points: 25

Up
0
Down
Hi Vuyiswa,

I think <BR> is the culprit, try not to pass it to the function.

Thanks,
Debata

Vuyiswamb, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 10/20/2011 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
I Have replaced it with

<a href="#" onclick="<%# String.Format("return showComment('{0}','{1}')", Replace(Eval("Field1").ToString(),Chr(13),""), Replace(Eval("Field2").ToString(),Chr(13),"")) %>">


<img src="../../Imgs/comment2.png" />
</a>


and it brought me this

<a href="#" onclick="return showComment('This is another

with a carriage return
and a differentone
','This
is the

reason that i did this>> ')">


but still its a Problem, how can trim the empty spaces in this


Thank you for posting at Dotnetfunda
[Administrator]

Vuyiswamb, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ndebata on: 10/20/2011 [Member] Starter | Points: 25

Up
0
Down
Hi Vuyiswa,

You are removing \n but still there are some \r
Please try to use
Regex.Replace(str, @"[\n|\r]", " ")
.

Vuyiswamb, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 10/20/2011 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
eish even after changing my code to this


    <a href="#" onclick="<%#  String.Format("return showComment('{0}','{1}')", Replace(Eval("Field1").ToString(),"[\n|\r]"," "), Replace(Eval("Field2").ToString(),"[\n|\r]"," ") ) %>">


<img src="../../Imgs/comment2.png" />
</a>


i still get this


   <a href="#" onclick="return showComment('This is another

with a carriage return
and a differentone
','This
is the

reason that i did this>> ')">




Thank you for posting at Dotnetfunda
[Administrator]

Vuyiswamb, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response