tags:

views:

197

answers:

3

I am very inexperienced with PHP and I've having trouble calling a mootools function.

Here's my code:

echo '<script language="JavaScript">'; 
echo "Sexy.error('Test!');"; 
echo '</script>';

When viewing source code looks like this:

<html> 
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
    <title>Bath Solutions</title> 

    <link xmlns="" href="html_includes/css/main.css?version=10.03.05" rel="stylesheet" type="text/css" media="all" /> 
    <link xmlns="" href="html_includes/mootools/Autocompleter.css?version=10.03.05" rel="stylesheet" type="text/css" media="screen" /> 

    <link xmlns="" href="html_includes/css/print.css?version=10.03.05" rel="stylesheet" type="text/css" media="print" /><link xmlns="" href="html_includes/css/schedule.css?version=10.03.05" rel="stylesheet" type="text/css" media="all" />   
    <script language="javascript" type="text/javascript" src="html_includes/mootools.js?version=10.03.05"></script> 
    <script language="javascript" type="text/javascript" src="html_includes/main.js.php?version=10.03.05"></script> 
    <script language="javascript" type="text/javascript" src="html_includes/datepicker.js?version=10.03.05"></script> 
    <script language="javascript" type="text/javascript" src="html_includes/mootools/Observer.js?version=10.03.05"></script> 
    <script language="javascript" type="text/javascript" src="html_includes/mootools/Autocompleter.js?version=10.03.05"></script> 
    <script language="javascript" type="text/javascript" src="html_includes/mootools/Autocompleter.Request.js?version=10.03.05"></script> 
    <script type="text/javascript" src="html_includes/mootools/sexyalert/sexyalertbox.v1.2.moo.js?version=10.03.05"></script> 
    <link rel="stylesheet" type="text/css" media="all" href="html_includes/mootools/sexyalert/sexyalertbox.css?version=10.03.05"/> 
    <script type="text/javascript" src="html_includes/fckeditor/fckeditor.js?version=10.03.05"></script> 

</head>
<body> 
<script language="JavaScript">Sexy.error('Test!');</script>
...

When I try it with a simple alert('test') it works just fine.. I'm confused?!?

UPDATE: I tried a calling the Sexy.error() onClick in an anchor tag and it works fine:

<a href="#" onclick="Sexy.error('test');return false;">click to test</a>  
A: 

You haven't specified your version of mootools, but according to this there is not error method. Try changing your code to:

echo '<script language="JavaScript">';   
echo "Sexy.alert('Test!');";   
echo '</script>';  

instead.

and remember to add this to your html too:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/mootools/1.2.1/mootools-yui-compressed.js"&gt;&lt;/script&gt;
<script type="text/javascript" src="sexyalertbox.v1.2.moo.js"></script>
<link rel="stylesheet" type="text/css" media="all" href="sexyalertbox.css"/>
klausbyskov
maybe I haven't had enough coffee yet but I don't see a difference in code...lol! It's not the includes as there all setup by index.php and I can see them when I view source
Mikey1980
Mikey1980
A: 

You have to learn how to use FireBug - will help you greatly in such cases.

Itay Moav
Thanks but I use dev verison of Chrome, and console is giving no clues
Mikey1980
+1  A: 

wrap the call into a domready

<script type="text/javascript">
window.addEvent("domready", function() {
    Sexy.error('test');
});
</script>

if the class depends on any part of the dom, like <div id='sexy'></div> being 'there', it won't work as is--at the time of running of the script block, the target div won't be available for DOM manipulations yet.

Dimitar Christoff
awesome you rock!
Mikey1980