Connecting Tech Pros Worldwide Forums | Help | Site Map

Problem with Error: Expected ')'...

Familiar Sight
 
Join Date: Oct 2007
Posts: 254
#1: Sep 10 '09
Hi all.

I have problem with this string javascript:

Expand|Select|Wrap|Line Numbers
  1. onclick="if(confirm('Confirm?')) location.href('form.asp?A=terry.d'arby'); return false;
The error javascript is:
Error: Expected ')'

Why? Can you help me?
Kind regards

Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,662
#2: Sep 10 '09

re: Problem with Error: Expected ')'...


Quote:

Originally Posted by viki1967 View Post

Can you help me?

sure, your url string is invalid, you have alltogether 5 unescaped ' in your line (is that 2 and a half strings?), thus the last ) is part of a string.
Familiar Sight
 
Join Date: Oct 2007
Posts: 254
#3: Sep 10 '09

re: Problem with Error: Expected ')'...


Quote:

Originally Posted by Dormilich View Post

sure, your url string is invalid, you have alltogether 5 unescaped ' in your line (is that 2 and a half strings?), thus the last ) is part of a string.

When resolve my problem?
thanks
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,662
#4: Sep 10 '09

re: Problem with Error: Expected ')'...


Quote:

Originally Posted by viki1967 View Post

When resolve my problem?

as soon as you can.

you have four options (I know of)
  • use the typographical apostrophe (U+2019)
  • use encodeURI()
  • nest the string (use " and ')
  • escape the non-delimiter '
Familiar Sight
 
Join Date: Oct 2007
Posts: 254
#5: Sep 10 '09

re: Problem with Error: Expected ')'...


thanks, but I try this and not working...

Expand|Select|Wrap|Line Numbers
  1. onclick="if(confirm('Confirm?')) location.href('Form.asp?A=' + encodeURIComponent(terry.d'arby) + '); return false;
  2.  
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,662
#6: Sep 10 '09

re: Problem with Error: Expected ')'...


well, you have 5 unescaped and 1 escaped ' (similar situation like before)
Familiar Sight
 
Join Date: Oct 2007
Posts: 254
#7: Sep 10 '09

re: Problem with Error: Expected ')'...


Quote:

Originally Posted by Dormilich View Post

well, you have 5 unescaped and 1 escaped ' (similar situation like before)

I don't understand.. sorry...
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,662
#8: Sep 10 '09

re: Problem with Error: Expected ')'...


hm, not sure how the return string of encodeURIComponent is treated.
Quote:

Originally Posted by MDC

encodeURIComponent escapes all characters except the following: alphabetic, decimal digits, - _ . ! ~ * ' ( )

what about
Expand|Select|Wrap|Line Numbers
  1. onclick="if(confirm('Confirm?')) location.href('Form.asp?A=' + encodeURIComponent(terry.d'arby) + '); return false;
Familiar Sight
 
Join Date: Oct 2007
Posts: 254
#9: Sep 10 '09

re: Problem with Error: Expected ')'...


Quote:

Originally Posted by Dormilich View Post

hm, not sure how the return string of encodeURIComponent is treated.

Not working:

Expand|Select|Wrap|Line Numbers
  1. onclick="if(confirm('Confirm?')) location.href('Form.asp?A=' + encodeURI(terry.d'arby) + '); return false;
Not working:
Expand|Select|Wrap|Line Numbers
  1. onclick="if(confirm('Confirm?')) location.href('Form.asp?A=encodeURI(terry.d'arby)); return false;
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,662
#10: Sep 10 '09

re: Problem with Error: Expected ')'...


think of what you wrote there.

Expand|Select|Wrap|Line Numbers
  1. onclick="if(confirm('Confirm?')) location.href('Form.asp?A=' + encodeURI(terry.d'arby) + '); return false;

Expand|Select|Wrap|Line Numbers
  1. onclick="if(confirm('Confirm?')) location.href('Form.asp?A=encodeURI(terry.d'arby)); return false;
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,662
#11: Sep 10 '09

re: Problem with Error: Expected ')'...


something that just popped to my attention:
Expand|Select|Wrap|Line Numbers
  1. location.href = new_URI;
  2. // not
  3. location.href(new_URI);
at least that’s what’s defined in the specs
Familiar Sight
 
Join Date: Oct 2007
Posts: 254
#12: Sep 10 '09

re: Problem with Error: Expected ')'...


Nothing...

Expand|Select|Wrap|Line Numbers
  1. onclick="if(confirm('Sure?')) location.href = 'Form.asp?A='+encodeURI(terry.d'arby)+''; return false;
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,662
#13: Sep 10 '09

re: Problem with Error: Expected ')'...


any error messages?


Familiar Sight
 
Join Date: Oct 2007
Posts: 254
#14: Sep 10 '09

re: Problem with Error: Expected ')'...


Quote:

Originally Posted by Dormilich View Post

any error messages?


Error: Expected ')' :(
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,662
#15: Sep 10 '09

re: Problem with Error: Expected ')'...


use one of the other two possibilities mentioned earlier.
Familiar Sight
 
Join Date: Oct 2007
Posts: 254
#16: Sep 10 '09

re: Problem with Error: Expected ')'...


I don't not use... any example please?
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,662
#17: Sep 10 '09

re: Problem with Error: Expected ')'...


Expand|Select|Wrap|Line Numbers
  1. \'

_____________
Reply