Solved

re: if logic in function

Posted on 2009-04-08
5
259 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

733 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