Connecting Tech Pros Worldwide Forums | Help | Site Map

Having trouble with iif and quotes

Familiar Sight
 
Join Date: Sep 2007
Posts: 221
#1: Jul 18 '08
I'm having an issue with quotes and double quotes on my iif statement. I'm trying to call a javascript function but can't seem to get the syntax correct. I know it's failing because I have this setup: <a href="javascript:alert('hi');">. I don't know how I can setup the quotes in order to get this working properly. It could just be friday, but I've been tinkering around with this, and am truly stumped now.

#iif(session.access eq 'admin',
DE("<li><a href="javascript:alert('hi');">Administration</a></li>"),DE(''))#

"an expression beginning with "iif", on line 72, column 14.This message is usually caused by a problem in the expressions structure."

acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#2: Jul 19 '08

re: Having trouble with iif and quotes


You need to escape the quotes:
Expand|Select|Wrap|Line Numbers
  1. #iif(session.access eq 'admin',
  2.             DE("<li><a href=\"javascript:alert('hi');\">Administration</a></li>"),DE(''))#
Not directly related to the problem, but I would avoid the javascript: protocol in href. Use something like:
Expand|Select|Wrap|Line Numbers
  1. <a href=\"##\" onclick=\"alert('hi');\">Administration</a>
The pound sign needs to be escaped too hence the double pound.
Familiar Sight
 
Join Date: Sep 2007
Posts: 221
#3: Jul 21 '08

re: Having trouble with iif and quotes


Quote:

Originally Posted by acoder

You need to escape the quotes:

Expand|Select|Wrap|Line Numbers
  1. #iif(session.access eq 'admin',
  2.             DE("<li><a href=\"javascript:alert('hi');\">Administration</a></li>"),DE(''))#
Not directly related to the problem, but I would avoid the javascript: protocol in href. Use something like:
Expand|Select|Wrap|Line Numbers
  1. <a href=\"##\" onclick=\"alert('hi');\">Administration</a>
The pound sign needs to be escaped too hence the double pound.

Excellent, thanks acoder!!!
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#4: Jul 21 '08

re: Having trouble with iif and quotes


You're welcome. Glad to help :)
Reply