![]() |
Classes and Prototype [HELP]
Hello,
I've made a 'comments' function on my website's user profile page, and when a comment is posted, it posts/appears instantly, with the magic of AJAX. I was looking through the Prototype API documents to see if they've added anything new to go along with the new 1.6 release. They've changed up there 'Class' function to make it easier to use. Now I've never actually never used classes, and not just in Javascript... in PHP neither. (I need to convince myself it's not too scary to start to learn it, lol) I decided to have a crack at the Prototype's class functions and I thought if I could get the concepts of it, I'll re-write my comment posting function to work with a class, that way I can add to it, like for when I want to delete comments in the same way. I did a little test, something simple: Code:
<a href="#" onclick="effect.show(); return false">Show</a> <a href="#" onclick="effect.hide(); return false">Hide</a>Here's my function: javascript Code:
html Code:
Quote:
If anybody has any idea on my situation, I look forward to a response from ya :) Thanks a lot! |
Your code looks fine. Have you made sure you've got the latest version of Prototype as you're using the latest syntax for creating class', which wont work with older versions.
I created a skeleton of your Comemnts class and it worked fine for me, so you could use this as a test. Code:
<html> |
I suppose the question is, what version of Prototype are you using, CMellor?
|
The newest one, 1.6.
I tried your code Karl but got some errors about the initialize function, which is weird because it looks good to me. I'll keep trying I guess... |
Weird, it just wasn't working with the inline event handler, so I used an Event.observer
Code:
Event.observe('post_comment', 'submit', function() {I have it so if the textarea is left blank upon submit, it will show an error and do nothing more, I'm using Spry, which has it's own method's of doing things. It's simply: Code:
if(Spry.Widget.Form.validate(this.form) == true) { |
Hmm, everything looks fine. What error are you getting and what line/section of code is the error pointing to.
|
| All times are GMT. The time now is 08:51 PM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0