Try this - I ran your code through JSLint, so not much magic on my
part:
var Comments = Class.create();
Comments.prototype = {
initialize: function(form) {
this.username = 'cmellor';
this.form = $(form);
},
// Post a comment
post: function() {
if(Spry.Widget.Form.validate(this.form) === true) {
var xhr = new Ajax.Updater('user_comments', 'configs/
ajax_functions.php?profile_comment=post', {
insertion: Insertion.Top,
parameters: {
user: this.username,
comment: $F('comment')
},
onLoading: function() {
$('comment_button').disable().value = 'Adding
Comment';
$('comment').clear().disable();
},
onSuccess: function() {
$('comment_button').value = 'Comment Posted';
}
});
}
}
};
The only major change I made is to use $() to make sure form is an
extended object, rather than a string.
Good luck!
On Nov 11, 8:03 pm, Chris <[EMAIL PROTECTED]> wrote:
> Dear all,
>
> I have decided to use the new Class function in the newest release of
> Prototype (1.6) and re-write a function I currently have, reason been
> for the simplicity to update it and to learn something new.
>
> I wrote this bit of code:
>
> var Comments = Class.create({
> initialize: function(form) {
> username = 'cmellor';
> this.form = form
> },
> // Post a comment
> post: function() {
> if(Spry.Widget.Form.validate(this.form) == true) {
> new Ajax.Updater('user_comments', 'configs/ajax_functions.php?
> profile_comment=post', {
> insertion: Insertion.Top,
> parameters: {
> user: username,
> comment: $F('comment')
> },
> onLoading: function() {
> $('comment_button').disable().value = 'Adding Comment';
> $('comment').clear().disable()
> },
> onSuccess: function() {
> $('comment_button').value = 'Comment Posted';
> }
> });
> }
> }
> });
>
> var comment = new Comments('post-comment');
>
> I use the code in a form tag using an onsubmit behaviour, like so:
>
> <form id="post-comment" onsubmit="comment.post(); return false">
>
> Something isn't right about this, because I submit the form, it
> refreshes and Firebug gives me the error "comment.post is not a
> function"
>
> Can somebody perhaps point out to me what I am doing wrong, any help
> would be appreciated :)
>
> Thank you,
>
> - Chris.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---