Solved

re: if logic in function

Posted on 2009-04-08
5
256 Views
Last Modified: 2012-05-06
i'm not sure where i'm going wrong here

I'm getting this error:
Parse error: syntax error, unexpected T_IF, expecting ';' or '{' in /home/cjehost/public_html/collectors_moment/libraries/joomla/html/html/behavior.php on line 63

thanks!
function caption() 

		if ($_GET['Itemid']=="54"){

			JHTML::script('caption2.js');

		}; else {

			JHTML::script('caption.js');

		};

Open in new window

0
Comment
Question by:phillystyle123
  • 3
5 Comments
 
LVL 19

Accepted Solution

by:
Michael701 earned 250 total points
ID: 24101662
try these
// this should work
 

function caption() 

{

                if ($_GET['Itemid']=="54"){

                        JHTML::script('caption2.js');

                } else {

                        JHTML::script('caption.js');

                };

}
 
 

// this also should work
 

function caption() 

{

                if ($_GET['Itemid']=="54")

                        JHTML::script('caption2.js');

                else

                        JHTML::script('caption.js');

                

}

Open in new window

0
 
LVL 10

Expert Comment

by:Phatzer
ID: 24101722
               }; else {

Indeed, get rid of that cheeky ';'
0
 
LVL 10

Expert Comment

by:Phatzer
ID: 24101731
Sorry, you don't need to have a ';' on closing brackets...
                if ($_GET['Itemid']=="54"){

                        JHTML::script('caption2.js');

                }; else {

                        JHTML::script('caption.js');

                };
 

Should be:
 

                if ($_GET['Itemid']=="54"){

                        JHTML::script('caption2.js');

                } else {

                        JHTML::script('caption.js');

                }

Open in new window

0
 
LVL 10

Expert Comment

by:Phatzer
ID: 24101752
Or... sorry for the repost:

I noticed that you hadn't got the 'caption() {' in your code, you just had 'caption()'
function caption() {

                if ($_GET['Itemid']=="54"){

                        JHTML::script('caption2.js');

                } else {

                        JHTML::script('caption.js');

                }

Open in new window

0
 

Author Closing Comment

by:phillystyle123
ID: 31568253
Thanks Michael701 - this seemed like the most elegant solution:

function caption()
{
                if ($_GET['Itemid']=="54")
                        JHTML::script('caption2.js');
                else
                        JHTML::script('caption.js');
               
}

aside from using too many ';' s - what was i doing wrong?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now