I revised my code example of creating a new note
This one attaches the submit event too the newly added form within the callback function
off the load event.
It's a step forward
because the other examples diddn't do the job, for some reason.
I don't know about any drawbacks off doing it like this, yet!!
I am open for any comments on the issue
If you want see example
Purpose&Comments:
The newnote function takes two arguments
-: index = the number off notes already present on the page
-: tbnoteid = the noteid from the database
The index is supposed too act like a counter of displayed messages.
If the counter exceeds 10 for example, it is supposed to delete the message on the criterium off last one is first one out (message with the oldest timestamp)from the page and the db(logic has too be added later)
The only action the form is permitted todo is delete the message from the database and remove itself(the container div) from the page.For estatic purposes it is first faded out.
The function can take more arguments like the message itself.
When user enters the page the newnote function should be called from another function that pulls the messages from the db if there are any.
The link too generate a new note will be replaced by the action off another form like this example
$(document).ready(function(){
$('a[name=modal]').click(function(e) { //the selector is for testing purpose
//Cancel the link behavior
e.preventDefault();
var $aantal = $("div.pane").size()
newnote($number+1,1); // second argument is supposed too come from the database
});
function newnote(index,tbnoteid) {
$("div.wrapper:last").after('<div class="wrapper"></div>');
$('.wrapper:last').load('tbnote.html .pane', function() {
$(".pane:last").prepend("testmessage"); //testpurpose
$('.pane:last #frmnoteid').val(tbnoteid);
$(this,".frm" ).attr('id' , index);
var $id = $(this).attr('id'); "); //testpurpose
$('.frm:last').submit(function(){
$.post("tbnotes.php",{
noteid: $("#frmnoteid").val(),
actie: "verwijder",
tijd: timestamp}, function(xml) {
addMessages(xml);
});
alert("Hello mijn id = " + $id );"); //testpurpose
$(this).parents(".pane").animate({ opacity: 'hide' }, "slow");
$(this).parents(".wrapper").remove();
return false;
});
});
}