i have defined couple of functions inside javascript work perfectly, when put inside prototype doesn't seem work.
wall.html:
<script type="text/javascript" src="jquery/jquery-1.4.4.js"> </script> <script type="text/javascript" src="src/commentmanager.js"> </script> <script type="text/javascript" src="src/reply.js"> </script> <script type="text/javascript" src="src/comment.js"> </script> <script type="text/javascript"> $(document).ready(function(){ commentmanager(); $("form#newmessage").submit(function(){ var message = $("input#newmessagetxt").val(); var newcomment = new comment(message); }); }); </script> </head> <body> <div class="message"> <form id="newmessage">> <input type="text" id="newmessagetxt" height="200px" value="write message" onfocus="if(this.value==this.defaultvalue) this.value='';" onblur="if(this.value=='') this.value=this.defaultvalue;" /> <input type="submit" value="submit" ></button> </form> </div> </body>
but weird part when run debugging tool in googlechrome, $("form#newmessage").submit doesn't call @ all. comment(message) never created (which have set prototype functions)
comment.js:
function comment(message){ var self = this; var message = message; var comment = document.createelement("li"); comment.id = "comment"; comment.textcontent = message; //empty reply field var replyfield = document.createelement("ul"); replyfield.id = "replyfield"; //create appropriate buttons createbuttons(comment); //append replyfield comment.appendchild(replyfield); //insert wall addcomment(comment); //effect after insertion effect(comment); $(comment).mouseleave(function() {mouseout(comment);}); $(comment).mouseenter(function() {mouseover(comment);}); return comment; } comment.prototype={ deletecomment : function (comment){ $(comment).fadeout(); settimeout(function() {comment.parentnode.removechild(comment);},500); }, //there more methods here }
commentmanager.js:
function commentmanager(){ var owner = null; var wall = document.createelement("ul"); wall.id = "wall"; document.body.appendchild(wall); return wall; } function addcomment(comment){ var wall = document.getelementbyid("wall"); wall.appendchild(comment); }
where createbuttons
defined? (in comment.js)?
also, you titled last file commentmanager.js, wall.html has commentmanager.js (notice capital m in wall.js). i'm assuming that's typo here in question, make sure filenames on server match html script tags.
Comments
Post a Comment