Class not defined

A

Alberto

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.
 
G

Gregor Kofler

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
 
R

RobG

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
 
A

Alberto

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>
 
A

Alberto

Alberto meinte:



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 said:
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.
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.
 
G

Gregor Kofler

Alberto meinte:
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?
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.

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

Gregor
 
J

John G Harris

On Tue, 29 Apr 2008 at 06:03:06, in comp.lang.javascript, Alberto wrote:

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
 
A

Alberto

Alberto meinte:



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


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?



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.
You're welcome.


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


Gregor

Thank you Gregor, I'll give it a try.
 
T

Thomas 'PointedEars' Lahn

Alberto said:
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
 
G

Gregor Kofler

Gregor Kofler meinte:
Alberto meinte:

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
 
A

Alberto

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?
 
G

Gregor Kofler

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top