Class not defined

Discussion in 'Javascript' started by Alberto, Apr 29, 2008.

  1. Alberto

    Alberto Guest

    Hi,

    I've implemented a customized autocompleter using prototypes and it
    actually works like a charm in Firefox, but in IE 6/7 it just doesn't
    work because that infernal thing says that 'Autocomp' (the class i
    created for the autocompleter) is 'not defined'.

    It's kind of weird because I tried to show an alert before of the
    class definition but it is not shown even though the error is thrown
    at the instantiation of the autocompleter.

    I was googling for more than a reasonable time but i did not found the
    cause... any help? Please consider that I'm using Portotype framework
    (I also tried its Class creation API but the result was the same) and
    Scriptaculous (its Ajax.Autocompleter worked without problems, but we
    need a more customized control in order to fit our needs).

    Thanks in advance.
     
    Alberto, Apr 29, 2008
    #1
    1. Advertising

  2. Alberto meinte:
    > Hi,
    >
    > I've implemented a customized autocompleter using prototypes and it
    > actually works like a charm in Firefox, but in IE 6/7 it just doesn't
    > work because that infernal thing says that 'Autocomp' (the class i
    > created for the autocompleter) is 'not defined'.
    > It's kind of weird because I tried to show an alert before of the
    > class definition but it is not shown even though the error is thrown
    > at the instantiation of the autocompleter.


    Classes in JS? No such thing...

    One should place the alert before the instantiation of the object. The
    definition can be "anywhere".

    > I was googling for more than a reasonable time but i did not found the
    > cause... any help? Please consider that I'm using Portotype framework
    > (I also tried its Class creation API but the result was the same) and
    > Scriptaculous (its Ajax.Autocompleter worked without problems, but we
    > need a more customized control in order to fit our needs).


    Eeek.
    Well, in this case I suggest to add a pinch of jQuery. And some mootools
    for good measure.

    > Thanks in advance.


    Seriously: What kind of help do you expect with such a problem
    description? Using some library (one which is regularly scrutinized in
    this NG) and posting no code whatsoever. Still, most likely the error
    occurs somewhere *before* your instantiation of your autocompleter.

    Gregor


    --
    http://photo.gregorkofler.at ::: Landschafts- und Reisefotografie
    http://web.gregorkofler.com ::: meine JS-Spielwiese
    http://www.image2d.com ::: Bildagentur für den alpinen Raum
     
    Gregor Kofler, Apr 29, 2008
    #2
    1. Advertising

  3. Alberto

    RobG Guest

    On Apr 29, 10:34 pm, Alberto <> wrote:
    > Hi,
    >
    > I've implemented a customized autocompleter using prototypes and it
    > actually works like a charm in Firefox, but in IE 6/7 it just doesn't
    > work because that infernal thing says that 'Autocomp' (the class i
    > created for the autocompleter) is 'not defined'.


    It is difficult to debug code that can't be seen. Reduce your code to
    the minimum that demonstrates the issue and post it.


    [...]
    > I was googling for more than a reasonable time but i did not found the
    > cause... any help? Please consider that I'm using Portotype framework
    > (I also tried its Class creation API but the result was the same) and
    > Scriptaculous (its Ajax.Autocompleter worked without problems, but we
    > need a more customized control in order to fit our needs).


    If you want help specifically with Prototype.js, better to ask in:

    <URL: http://groups.google.com.au/group/rubyonrails-spinoffs?hl=en&lnk=li
    >



    --
    Rob
     
    RobG, Apr 29, 2008
    #3
  4. Alberto

    Alberto Guest

    Here is a DHTML sample file. Note that response of autocomplete.php
    should be a table like this:

    <table>
    <tr><th>Field 1</th><th>Field 2</th><th>Field 3</th></tr>
    <tr class="autocompleteFila"><td>XXXX</td><td><span
    class="autocompleteInput">YYYY</span><span
    class="autocompleteRet">ZZZZZ</span></td><td>AAAA</td></tr>
    <tr class="autocompleteFila"><td>XXXX</td><td><span
    class="autocompleteInput">YYYY</span><span
    class="autocompleteRet">ZZZZZ</span></td><td>AAAA</td></tr>
    <tr class="autocompleteFila"><td>XXXX</td><td><span
    class="autocompleteInput">YYYY</span><span
    class="autocompleteRet">ZZZZZ</span></td><td>AAAA</td></tr>
    <tr class="autocompleteFila"><td>XXXX</td><td><span
    class="autocompleteInput">YYYY</span><span
    class="autocompleteRet">ZZZZZ</span></td><td>AAAA</td></tr>
    </table>

    Sample HTML file is:

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://
    www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <script type="text/javascript" src="/lib/prototype/prototype.js"></
    script>
    </head>
    <body>
    <script type="text/javascript">
    /*<[CDATA[*/
    alert('HOLA');

    var Autocomp = function(inputField, returnField, class, rowClass,
    returnClass, returnToInputClass, url, reqParam) {
    this.idField = inputField;
    this.returnField = returnField;
    this.cssClass = class;
    this.url = url;
    this.cssRowClass = rowClass;
    this.cssReturnClass = returnClass;
    this.cssToInputClass = returnToInputClass;
    this.reqParam = reqParam;
    this.configure();
    }

    Autocomp.prototype.load = function(query) {
    var complete = function(transport) {
    var numRes = 0;
    var f = $(this.returnField);
    var input = $(this.idField);
    var div = this.div;
    var claseRet = this.cssReturnClass;
    var claseInputRet = this.cssToInputClass;
    this.div.innerHTML = transport.responseText;
    this.div.select('.'+this.cssRowClass).each(
    function (elem) {
    numRes++;
    Event.observe(elem, 'click', function (e) {
    f.value = elem.select('.'+claseRet).reduce().innerHTML;
    input.value = elem.select('.'+claseInputRet).reduce().innerHTML;
    div.hide();
    });
    });

    if(numRes == 0) {
    this.div.hide();
    }
    else {
    this.div.show();
    }
    }

    var h = $H(this.reqParam);
    new Ajax.Request(this.url + '?'+ h.toQueryString() + '&query=' +
    escape(query),
    {
    method: 'get',
    onComplete: complete.bind(this)
    });
    }

    Autocomp.prototype.configure = function() {
    var f = $(this.idField);
    var onKeyPress = function (event) {
    if(f.value.length >= 3) {
    this.load(f.value)
    }
    else {
    this.div.hide();
    }
    };

    var onFocus = function (event) {
    f.clear();
    };

    Event.observe(f, 'keyup', onKeyPress.bindAsEventListener(this));
    Event.observe(f, 'focus', onFocus.bindAsEventListener(this));

    this.div = new Element('div', {'class': this.cssClass, 'style': 'z-
    index: 1000; position: absolute; display: none; top: 0px; left:
    0px'});
    f.insert({after: this.div});
    this.div.clonePosition(f, {setWidth: false, setHeight: false,
    offsetTop: f.getHeight()});
    }

    alert('HOLA');
    /*]]>*/
    </script>
    <input maxlength="100" type="text" id="txtOrigenOfe"
    name="txtOrigenOfe" style="width:180px" value="">
    <script type="text/javascript">
    /*<[CDATA[*/
    var a = new Autocomp('txtOrigenOfe', 'txtOrigenOfe', 'autocomplete',
    'autocompleteFila', 'autocompleteRet', 'autocompleteInput', '/
    autocomplete.php', {foo: 'bar'});
    /*]]>*/
    </script>
    </body>
    </html>
     
    Alberto, Apr 29, 2008
    #4
  5. Alberto

    Alberto Guest

    On 29 abr, 14:54, Gregor Kofler <> wrote:
    > Alberto meinte:
    >
    > > Hi,

    >
    > > I've implemented a customized autocompleter using prototypes and it
    > > actually works like a charm in Firefox, but in IE 6/7 it just doesn't
    > > work because that infernal thing says that 'Autocomp' (the class i
    > > created for the autocompleter) is 'not defined'.
    > > It's kind of weird because I tried to show an alert before of the
    > > class definition but it is not shown even though the error is thrown
    > > at the instantiation of the autocompleter.

    >
    > Classes in JS? No such thing...


    FALSE, extending the prototype in JS is usually done to simulate OO
    behavior. Not real classes, but really useful ones.

    > One should place the alert before the instantiation of the object. The
    > definition can be "anywhere".


    The confusing thing here is that IE seems to ignore the whole
    definition <script> block.

    >
    > > I was googling for more than a reasonable time but i did not found the
    > > cause... any help? Please consider that I'm using Portotype framework
    > > (I also tried its Class creation API but the result was the same) and
    > > Scriptaculous (its Ajax.Autocompleter worked without problems, but we
    > > need a more customized control in order to fit our needs).

    >
    > Eeek.
    > Well, in this case I suggest to add a pinch of jQuery. And some mootools
    > for good measure.


    Not asking for opinion, just for some concrete help.

    >
    > > Thanks in advance.

    >
    > Seriously: What kind of help do you expect with such a problem
    > description? Using some library (one which is regularly scrutinized in
    > this NG) and posting no code whatsoever. Still, most likely the error
    > occurs somewhere *before* your instantiation of your autocompleter.


    Well, not this kind of help of course. As I posted, I was googling,
    which also implies looking for info in groups, as this one. I usually
    don't need to post in groups asking about this kind of stuff, but
    look! Today I had to.

    Thanks anyway for posting.

    > Gregor
    >
    > --http://photo.gregorkofler.at::: Landschafts- und Reisefotografiehttp://web.gregorkofler.com ::: meine JS-Spielwiesehttp://www.image2d.com ::: Bildagentur für den alpinen Raum
     
    Alberto, Apr 29, 2008
    #5
  6. Alberto meinte:
    > On 29 abr, 14:54, Gregor Kofler <> wrote:
    >> Alberto meinte:
    >>
    >>> Hi,
    >>> I've implemented a customized autocompleter using prototypes and it
    >>> actually works like a charm in Firefox, but in IE 6/7 it just doesn't
    >>> work because that infernal thing says that 'Autocomp' (the class i
    >>> created for the autocompleter) is 'not defined'.
    >>> It's kind of weird because I tried to show an alert before of the
    >>> class definition but it is not shown even though the error is thrown
    >>> at the instantiation of the autocompleter.

    >> Classes in JS? No such thing...

    >
    > FALSE, extending the prototype in JS is usually done to simulate OO
    > behavior. Not real classes, but really useful ones.


    Still: No classes. Douglas Crockford will tell you about the differences
    between classes and prototypal inheritance.


    > The confusing thing here is that IE seems to ignore the whole
    > definition <script> block.


    I suppose because of the errors in the code. Pasting it into JSEclipse
    gives me:

    "missing formal parameter" and "identifier is a reserved word"

    Guess what? "class" is a reserved word - at least for IE.

    Entering:

    javascript:var class="42";alert(class); into the adress field of IE gives me
    "Row 1 character 5 identifier expected ..."

    That was easy, wasn't it?

    >> Seriously: What kind of help do you expect with such a problem
    >> description? Using some library (one which is regularly scrutinized in
    >> this NG) and posting no code whatsoever. Still, most likely the error
    >> occurs somewhere *before* your instantiation of your autocompleter.

    >
    > Well, not this kind of help of course. As I posted, I was googling,
    > which also implies looking for info in groups, as this one. I usually
    > don't need to post in groups asking about this kind of stuff, but
    > look! Today I had to.


    With this attitude, the "problem" and your way to approach it, you sound
    like a script kiddie.

    > Thanks anyway for posting.


    You're welcome.

    >> --http://photo.gregorkofler.at::: Landschafts- und Reisefotografiehttp://web.gregorkofler.com ::: meine JS-Spielwiesehttp://www.image2d.com ::: Bildagentur für den alpinen Raum


    ....oh well, you hardly ever use usenet.

    Gregor


    --
    http://photo.gregorkofler.at ::: Landschafts- und Reisefotografie
    http://web.gregorkofler.com ::: meine JS-Spielwiese
    http://www.image2d.com ::: Bildagentur für den alpinen Raum
     
    Gregor Kofler, Apr 29, 2008
    #6
  7. On Tue, 29 Apr 2008 at 06:03:06, in comp.lang.javascript, Alberto wrote:

    <snip>
    >Sample HTML file is:
    >
    ><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://
    >www.w3.org/TR/html4/loose.dtd">
    ><html>
    ><head>
    ><script type="text/javascript" src="/lib/prototype/prototype.js"></
    >script>
    ></head>
    ><body>
    ><script type="text/javascript">
    >/*<[CDATA[*/
    >alert('HOLA');
    >
    >var Autocomp = function(inputField, returnField, class, rowClass,

    ^^^^^
    >returnClass, returnToInputClass, url, reqParam) {

    <snip>

    'class' is a reserved word. It mustn't be used as an identifier.

    John
    --
    John Harris
     
    John G Harris, Apr 29, 2008
    #7
  8. Alberto

    Alberto Guest

    On 29 abr, 20:18, Gregor Kofler <> wrote:
    > Alberto meinte:
    >
    > > On 29 abr, 14:54, Gregor Kofler <> wrote:
    > >> Alberto meinte:

    >
    > >>> Hi,
    > >>> I've implemented a customized autocompleter using prototypes and it
    > >>> actually works like a charm in Firefox, but in IE 6/7 it just doesn't
    > >>> work because that infernal thing says that 'Autocomp' (the class i
    > >>> created for the autocompleter) is 'not defined'.
    > >>> It's kind of weird because I tried to show an alert before of the
    > >>> class definition but it is not shown even though the error is thrown
    > >>> at the instantiation of the autocompleter.
    > >> Classes in JS? No such thing...

    >
    > > FALSE, extending the prototype in JS is usually done to simulate OO
    > > behavior. Not real classes, but really useful ones.

    >
    > Still: No classes. Douglas Crockford will tell you about the differences
    > between classes and prototypal inheritance.
    >
    > > The confusing thing here is that IE seems to ignore the whole
    > > definition <script> block.

    >
    > I suppose because of the errors in the code. Pasting it into JSEclipse
    > gives me:
    >
    > "missing formal parameter" and "identifier is a reserved word"
    >
    > Guess what? "class" is a reserved word - at least for IE.
    >
    > Entering:
    >
    > javascript:var class="42";alert(class); into the adress field of IE gives me
    > "Row 1 character 5 identifier expected ..."
    >
    > That was easy, wasn't it?
    >
    > >> Seriously: What kind of help do you expect with such a problem
    > >> description? Using some library (one which is regularly scrutinized in
    > >> this NG) and posting no code whatsoever. Still, most likely the error
    > >> occurs somewhere *before* your instantiation of your autocompleter.

    >
    > > Well, not this kind of help of course. As I posted, I was googling,
    > > which also implies looking for info in groups, as this one. I usually
    > > don't need to post in groups asking about this kind of stuff, but
    > > look! Today I had to.

    >
    > With this attitude, the "problem" and your way to approach it, you sound
    > like a script kiddie.
    >


    Not exactly, just switched from a hardcore J2EE position to a Web 2.0
    one. Sorry for being rude, sincerely.

    > > Thanks anyway for posting.

    >
    > You're welcome.
    >
    > >> --http://photo.gregorkofler.at:::Landschafts- und Reisefotografiehttp://web.gregorkofler.com::: meine JS-Spielwiesehttp://www.image2d.com ::: Bildagentur für den alpinen Raum

    >
    > ...oh well, you hardly ever use usenet.


    Touché.

    >
    > Gregor


    Thank you Gregor, I'll give it a try.
     
    Alberto, Apr 29, 2008
    #8
  9. Alberto

    Alberto Guest

    Thank you John, but if I change 'class' for another name (like
    'divClass') it still doesn't work.

    After the code change it still doesn't work. Just give it a try if you
    don't mind at this url:

    http://www.alu.ua.es/a/asb19/autocompleter.zip

    Thank you in advance.
     
    Alberto, Apr 29, 2008
    #9
  10. Alberto

    Alberto Guest

    Alberto, Apr 29, 2008
    #10
  11. Alberto wrote:
    > On 29 abr, 14:54, Gregor Kofler <> wrote:
    >> Alberto meinte:
    >>> [...]
    >>> It's kind of weird because I tried to show an alert before of the
    >>> class definition but it is not shown even though the error is thrown
    >>> at the instantiation of the autocompleter.

    >> Classes in JS? No such thing...

    >
    > FALSE, extending the prototype in JS is usually done to simulate OO
    > behavior. Not real classes, but really useful ones.


    You have been misled by the Prototype.js author's falling victim to the
    common misconception that prototype-based inheritance would not be an
    application of the object-oriented programming paradigm.

    Hopefully now you can begin to appreciate me and others repeatedly calling
    Prototype.js junk before. You may search the archives of this newsgroup for
    more insight. You should have done this before you posted, see
    http://jibbering.com/faq/ pp.


    PointedEars
    --
    realism: HTML 4.01 Strict
    evangelism: XHTML 1.0 Strict
    madness: XHTML 1.1 as application/xhtml+xml
    -- Bjoern Hoehrmann
     
    Thomas 'PointedEars' Lahn, Apr 30, 2008
    #11
  12. Alberto meinte:
    > Hi again,
    >
    > Unfortunately, after following your advice it still remains the same.
    > Pleas give a try if you don't mind from this package:
    >
    > http://www.alu.ua.es/a/asb19/autocompleter.zip


    Are you sure, that you got the proper files? index.html has a typo,
    therefore it can't load autocomplete*r*.js

    Gregor



    --
    http://photo.gregorkofler.at ::: Landschafts- und Reisefotografie
    http://web.gregorkofler.com ::: meine JS-Spielwiese
    http://www.image2d.com ::: Bildagentur für den alpinen Raum
     
    Gregor Kofler, Apr 30, 2008
    #12
  13. Gregor Kofler meinte:
    > Alberto meinte:
    >> Hi again,
    >>
    >> Unfortunately, after following your advice it still remains the same.
    >> Pleas give a try if you don't mind from this package:
    >>
    >> http://www.alu.ua.es/a/asb19/autocompleter.zip

    >
    > Are you sure, that you got the proper files? index.html has a typo,
    > therefore it can't load autocomplete*r*.js


    After fixing the typo: What am I supposed to see? In both IE and FF I
    get an input element. Finito. No errors, no AJAX, no nothing else.

    Gregor


    --
    http://photo.gregorkofler.at ::: Landschafts- und Reisefotografie
    http://web.gregorkofler.com ::: meine JS-Spielwiese
    http://www.image2d.com ::: Bildagentur für den alpinen Raum
     
    Gregor Kofler, Apr 30, 2008
    #13
  14. Alberto

    Alberto Guest

    Sorry for the typo, but anyway, after correcting it, as you said it
    does not work, but only in Firefox, try again. That's funny. I've
    really seen this autocompleter working in Firefox, it never did in IE,
    but now, after mentioned corrections it fails in FF ('Autocomp is not
    defined') and seems to load in IE, but not working as it should.

    Package at http://www.alu.ua.es/a/asb19/autocompleter.zip has been
    corrected.

    Any ideas?
     
    Alberto, Apr 30, 2008
    #14
  15. Alberto

    Alberto Guest

    I already did.

    Regards.
     
    Alberto, Apr 30, 2008
    #15
  16. Alberto meinte:
    > Sorry for the typo, but anyway, after correcting it, as you said it
    > does not work, but only in Firefox, try again. That's funny. I've
    > really seen this autocompleter working in Firefox, it never did in IE,
    > but now, after mentioned corrections it fails in FF ('Autocomp is not
    > defined') and seems to load in IE, but not working as it should.
    >
    > Package at http://www.alu.ua.es/a/asb19/autocompleter.zip has been
    > corrected.


    Trying to help you, is *no fun*.

    "Autocomp is not defined" - index.html line 11. Firefox (and all others,
    too)

    > Any ideas?


    Ok. Typo fixed. FF reports a 404 on the XHR response. Seems as if you
    fixed the wrong typo.
    Ok. Second typo fixed, path corrected.

    What now? Works ok in FF *AND* IE. What was your question?

    Gregor

    --
    http://photo.gregorkofler.at ::: Landschafts- und Reisefotografie
    http://web.gregorkofler.com ::: meine JS-Spielwiese
    http://www.image2d.com ::: Bildagentur für den alpinen Raum
     
    Gregor Kofler, Apr 30, 2008
    #16
  17. Alberto

    Alberto Guest

    It's working now.

    A thousand thanks, Gregor and everybody.
     
    Alberto, Apr 30, 2008
    #17
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. James Ying
    Replies:
    2
    Views:
    619
    James Ying
    Oct 28, 2003
  2. Oodini
    Replies:
    1
    Views:
    1,838
    Keith Thompson
    Sep 27, 2005
  3. Angel Tsankov
    Replies:
    1
    Views:
    897
    Victor Bazarov
    Apr 5, 2006
  4. Replies:
    1
    Views:
    539
    Sion Arrowsmith
    Jul 10, 2008
  5. Keith Thompson

    Re: __STDC_IEC_559__ (defined or !defined ?)

    Keith Thompson, Aug 17, 2010, in forum: C Programming
    Replies:
    0
    Views:
    462
    Keith Thompson
    Aug 17, 2010
Loading...

Share This Page