TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 12-04-2008, 01:16 AM   #1 (permalink)
The Wanderer
 
Join Date: Dec 2008
Posts: 9
Thanks: 0
almac007 is on a distinguished road
Default Getting Error: is not a function when viewed in firefox - works in IE

Hi Guys,

Could someone please help me...

I am trying to fix up the site www.thinkpharmacy.com.au

On the right hand side of the home page there are some ads whcih are randomly generated. If you are browsing with Internet Explorer and you click one of these ads you get taken to that particular products page. everything works fine.

The problem i am having is that if i am browsing the site using Firefox and i click one of the ads all i get the following error message...

Error: gid("linkAds" + adsClicked).click is not a function
Source File: http://www.thinkpharmacy.com.au/js/ads.js
Line: 85


I cant understand why this is not working.

Here is a copy of the script ads.js that is being called.

javascript Code:
var xmlHttpAds
   
    function stateChangedAds()
        {
            if (xmlHttpAds.readyState==4)
            {
                //tamResp = xmlHttpAds.responseText.toString().length;
                //if(tamResp > 1){
                    openAds();
                    //alert(xmlHttpAds.responseText);
                    //xmlHttpAds = null;
                //}
            }
        }
       
    function GetxmlHttpObjectAds()
        {
        var xmlHttpAds=null;
        try
          {
          // Firefox, Opera 8.0+, Safari
          xmlHttpAds=new XMLHttpRequest();
          }
        catch (e)
          {
          // Internet Explorer
          try
            {
            xmlHttpAds=new ActiveXObject("Msxml2.XMLHTTP");
            }
          catch (e)
            {
            xmlHttpAds=new ActiveXObject("Microsoft.XMLHTTP");
            }
          }
        return xmlHttpAds;
    }
    var product = '';
    var adsClicked = '';
    var Urlproduct = '';
    function updateAds(id,product_id,Url){
        adsClicked = id;
        xmlHttpAds = GetxmlHttpObjectAds();
        var url = "";
        // DMD - 20060626 - get the host info
        // and make the URL
        switch(window.location.hostname)
        {
        case 'www.thinkpharmacy.com.au':
          var serverNameURL = "http://www.thinkpharmacy.com.au";
          break;   
        case 'tpo.thinkpharmacy.com.au':
          var serverNameURL = "https://tpo.thinkpharmacy.com.au";
          break;
        case 'www.productezine.com':
          var serverNameURL = "https://www.productezine.com/testserver/think";
          break;
        default:
          var serverNameURL = "";
        }
        //alert('passed in is ' + window.location.hostname);
        //alert('servernameurl is ' + serverNameURL);
        // var url="http://www.productezine.com/testserver/think/ajax/updateAds.php?id="+id;
        var url=serverNameURL+"/ajax/updateAds.php?id="+id; 
       
        var url2="http://www.thinkpharmacy.com.au/ajax/updateAds.php?id="+id;   
    //  alert('url2 is ' + url2);
       
        // DMD Edit
    //  alert(url);
        product = product_id;
        xmlHttpAds.onreadystatechange=stateChangedAds;
    //  alert('before redirect');
        xmlHttpAds.open("GET",url,true);
    //  alert('after redirect');
        xmlHttpAds.send(null);
        Urlproduct = Url;
    //  alert('URL Product is ' + Urlproduct);
    }

    function openAds(){
        if(Urlproduct == ""){
            gid("linkAdsProd"+adsClicked).click();
        }else{
            gid("linkAds"+adsClicked).click();
        }
    }


if anybody could help me out i would be very apprieciative.

Thanks in advance,

Almac007

Last edited by Wildhoney : 12-04-2008 at 01:53 AM.
almac007 is offline  
Reply With Quote
Old 12-04-2008, 01:58 AM   #2 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

I don't see how that can work in any browser, if that's the exact code you're using. You're missing curly brackets, and also the function syntax for those classes are wrong. The syntax is as so:

javascript Code:
var TalkPHP =
{
    MyFunction1: function()
    {
        alert('My Function 1');
    },

    MyFunction2: function()
    {
        alert('My Function 2');
    }
}

TalkPHP.MyFunction1();
TalkPHP.MyFunction2();

Are you certain that's the precise code that you're using?
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 12-04-2008, 02:03 AM   #3 (permalink)
The Wanderer
 
Join Date: Dec 2008
Posts: 9
Thanks: 0
almac007 is on a distinguished road
Default

Hi Wildhoney,

Thanks for getting back to me.

Yeah that is the code cut and pasted from teh script. I was not the one who wrote it and am simply trying to fix it.

When you say that function brackets are missing are you referring to var xmlHttpAds?

and if so would it be something like

var xmlHttpAds =
{

...functions in here.
}

Thanks again for your help.

almac007
almac007 is offline  
Reply With Quote
Old 12-04-2008, 02:24 AM   #4 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

Yep, that's the one! And also reverse the function and function names, as seen below. Hopefully this should get it working, but don't hesitate to re-paste the new code if it still doesn't work.

javascript Code:
/* Don't forget the equals symbol. */
var TalkPHP =
{
    /* This is the RIGHT way. */
    MyFunction1: function()
    {
        alert('My Function 1');
    },
    /* Don't forget a comma at the end of
    a function, before you start another. */


    /* This is the WRONG way. */
    /* Don't forget the colon after "function" */
    function: MyFunction2()
    {
        alert('My Function 2');
    }
    /* No need for a comma here unless you're
    adding another function below it. */

}

Remember: functionName: function()
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 12-04-2008, 04:15 AM   #5 (permalink)
The Wanderer
 
Join Date: Dec 2008
Posts: 9
Thanks: 0
almac007 is on a distinguished road
Default

Hi Wildhoney,

Thanks for all your help with this.

I have rewritten the code but now i cant get it to work in either IE or Firefox. I keep getting the follwoing error.

Error: updateAds is not defined
Source File: javascript:updateAds('73','0','/prodinfo.php?id=1252')
Line: 1

Its probably something really simple :(

here is a copy of the rewritten code.

var xmlHttpAds =
{

var product = '';
var adsClicked = '';
var Urlproduct = '';

stateChangedAds: function()
{
if (xmlHttpAds.readyState==4)
{
openAds();
}
},
GetxmlHttpObjectAds: function()
{
var xmlHttpAds=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttpAds=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttpAds=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttpAds=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttpAds;
},
updateAds: function(id,product_id,Url)
{
adsClicked = id;
xmlHttpAds = GetxmlHttpObjectAds();
var url = "";
// DMD - 20060626 - get the host info
// and make the URL
switch(window.location.hostname)
{
case 'www.thinkpharmacy.com.au':
var serverNameURL = "https://www.thinkpharmacy.com.au";
break;
case 'tpo.thinkpharmacy.com.au':
var serverNameURL = "https://tpo.thinkpharmacy.com.au";
break;
case 'www.productezine.com':
var serverNameURL = "https://www.productezine.com/testserver/think";
break;
default:
var serverNameURL = "";
}

var url=serverNameURL+"/ajax/updateAds.php?id="+id;

product = product_id;
xmlHttpAds.onreadystatechange=stateChangedAds;
xmlHttpAds.open("GET",url,true);
xmlHttpAds.send(null);
Urlproduct = Url;
},
openAds: function()
{
if(Urlproduct == ""){
gid("linkAdsProd"+adsClicked).click();
}else{
gid("linkAds"+adsClicked).click();
}
}
}


thanks again for your help.
almac007 is offline  
Reply With Quote
Old 12-04-2008, 03:18 PM   #6 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

I think it has more to do with the fact that you are using an object literal, yet are still trying to assign variables in a normal fashion.
javascript Code:
obj = {
    var test = '';
    var test2 = '';
}
is incorrect, this is the correct way and looks similar to the methods:
javascript Code:
obj = {
    test : '',
    test2 : '',
}
Basically (looking at the error from your site currently) JS is trying to interpret 'var' as a property of the object, then it will look for ':' to assign a value to it but it cant find it. Also you don't assign properties with values in that way, you assign them like functions (in theory you are with methods, assigning an anonymous function to a object property) also the comma at the end is important too.
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)

Last edited by sketchMedia : 12-04-2008 at 03:21 PM. Reason: oops
sketchMedia is offline  
Reply With Quote
Old 12-04-2008, 04:48 PM   #7 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

Are you guys seeing the same code as me (in the original post)? I don't see a badly-written object, but a number of separate functions (4) and variables (4) in the global scope.
Salathe is offline  
Reply With Quote
Old 12-04-2008, 05:00 PM   #8 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

rofl, i must admit i only scan read it.
Sigh its been a long day.

anyway the real error must be something to do with 'gid', is 'click' a property or a method? try knocking the '()' off the end. where is 'gid' defined?
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
Old 12-04-2008, 11:19 PM   #9 (permalink)
The Wanderer
 
Join Date: Dec 2008
Posts: 9
Thanks: 0
almac007 is on a distinguished road
Default

Hi Salathe,

So should i be using the code from the original post or use the code that i have rewritten in the above post?

The code from the original post works in IE but not in firefox, where as the rewritten code does not work in either browser. :(

Thanks for all your help guys. This forum is great!

Cheers,

Almac007
almac007 is offline  
Reply With Quote
Old 12-05-2008, 09:27 AM   #10 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

After looking over your code, i noticed that 'gid' returns a ref to and element via getElementById(), as a result you will need to re write this:
javascript Code:
function openAds(){
    if(Urlproduct == ""){
        gid("linkAdsProd"+adsClicked).click();
    }else{
        gid("linkAds"+adsClicked).click();
    }
}
As the 'elementRef.click()' method doesn't work in FF.

Your old code should be fine.

EDIT:
Im assuming that the element returned by gid in this case is a link of some sort? if so you could do something like this
javascript Code:
function openAds(){
    if(Urlproduct == ""){
        window.location = gid("linkAdsProd"+adsClicked).href;
    }else{
        window.location = gid("linkAds"+adsClicked).href;
    }   
}
I havent tested, i just thought it up now.
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to create a gallery class Tanax Advanced PHP Programming 25 02-19-2013 04:25 AM
Timezone Class: Dealing with Timezones the Proper Way Wildhoney General 2 01-10-2011 11:01 PM
Part 2: Giving our Currency Conversion Script some Responsibility Wildhoney General 15 03-17-2009 01:53 PM
[Tutorial] How to organize your classes | Part 1 Tanax Advanced PHP Programming 10 03-01-2009 10:08 PM
The hello world contest Village Idiot The Lounge 9 01-07-2008 02:15 PM


All times are GMT. The time now is 02:23 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design