To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
PHPBuilder.com  
 

 

Go Back   PHPBuilder.com > Misc Help > ClientSide Technologies

ClientSide Technologies Discuss HTML/CSS/Javascript, and any other client-side technologies, here.

Reply
 
Thread Tools Rate Thread Display Modes
Old 11-07-2009, 09:30 PM   #1
Kudose
Fatal Error Line 0
 
Kudose's Avatar
 
Join Date: Feb 2003
Location: Kansas City
Posts: 3,817
resolved [RESOLVED] function undefined

'ello all.

I have the following bit of code that is included into a full valid XHTML page via MooTools load()

PHP Code:
<?php

  
require_once('../conf.php');

  if(!
$player)
    die(
'Please login');

?>
Welcome to the elevator.  Sometimes the elevator gets full and you have to wait, so change floors quickly!
<br />
<br />
<strong id="floor_elevator">You are currently on floor <?php echo $player->getFloor(); ?></strong>
<br />
<br />
<ul>
  <li onclick="javascript:changeFloor(1);" class="hover">1<sup>st</sup> Floor</li>
  <li onclick="javascript:changeFloor(2);" class="hover">2<sup>nd</sup> Floor</li>
</ul>
<script type="text/javascript">
  function changeFloor(newFloor){
    if(!newFloor){
      alert('Invalid floor.');
      return false;
    }
    var req = new Request.HTML({url:'pages/elevator-ajax.php', onSuccess(els, tree, html){
      $('floor_elevator').innerHTML = html;
    }}).send('floor=' + newFloor);
  }
</script>
The problem is that when I click one of the LI elements above, I get a function changeFloor is undefined error.

Anyone know why?

TIA!
__________________
Problem Solved? Mark this thread resolved using the Thread Tools.
Apache HQ | PHP HQ | Smarty HQ | MySQL HQ | Spechal Blog | LinkedIn
0100001001111001011101000110010100100000011011010110010100100001
Kudose is offline   Reply With Quote
Old 11-07-2009, 10:57 PM   #2
Kudose
Fatal Error Line 0
 
Kudose's Avatar
 
Join Date: Feb 2003
Location: Kansas City
Posts: 3,817
I figured it out ... my MooTools onSuccess was wrong ... I don't know why it would cause the function to be undefined though.

Should be:

Code:
<script type="text/javascript">
  function changeFloor(newFloor){
    if(!newFloor){
      alert('Invalid floor.');
      return false;
    }
    var req = new Request.HTML({url:'pages/elevator-ajax.php', onSuccess:function(els, tree, html){
      $('floor_elevator').innerHTML = html;
    }}).send('floor=' + newFloor);
  }
</script>
__________________
Problem Solved? Mark this thread resolved using the Thread Tools.
Apache HQ | PHP HQ | Smarty HQ | MySQL HQ | Spechal Blog | LinkedIn
0100001001111001011101000110010100100000011011010110010100100001
Kudose is offline   Reply With Quote
Old 11-08-2009, 03:50 AM   #3
Weedpacket
Custom User Title™
 
Weedpacket's Avatar
 
Join Date: Aug 2002
Location: Rapid Offensive Unit "Foreign Object Damage"
Posts: 19,122
I see what the problem is. onSuccess(els,tree,html) is bad syntax there (the parser interprets "onSuccess" as a property ID, as it should, but then it expects to see a ':' - not a '('. And since changeFloor() contains bad syntax, it doesn't get defined.
__________________
On two occasions I have been asked [by Members of Parliament], "Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?" I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question.
Weedpacket is offline   Reply With Quote
Old 11-09-2009, 12:45 AM   #4
Kudose
Fatal Error Line 0
 
Kudose's Avatar
 
Join Date: Feb 2003
Location: Kansas City
Posts: 3,817
That explains it! Thanks!
__________________
Problem Solved? Mark this thread resolved using the Thread Tools.
Apache HQ | PHP HQ | Smarty HQ | MySQL HQ | Spechal Blog | LinkedIn
0100001001111001011101000110010100100000011011010110010100100001
Kudose is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -4. The time now is 09:28 AM.






Acceptable Use Policy

internet.comMediabistrojusttechjobs.comGraphics.com

WebMediaBrands Corporate Info


Advertise | Newsletters | Feedback | Submit News

Legal Notices | Licensing | Permissions | Privacy Policy


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.