.js[code] var Comment = { onCommentSubmit:function( el, url, targetEl ) { var data = $(el).serialize(); var type = "POST"; Star.ajax( type, el, url, data, targetEl ); return false; }
} var Star = { ajax:function( type, el, url, data, targetEl ) { $.ajax({ type: type, beforeSend:function(){ $(el).children(".button_parent").hide(); $(el).children(".ajax_loader").show(); }, url: url, data: data, success:function(txt){ $(el).children(".ajax_loader").hide(); $(el).children(".button_parent").show(); if(txt == "OK") { loadContents(targetEl, "/p_gamma/news/rq/r_latest_comments.php? id=" + $(el).children("input[name='id']").val()); } }, error:function(txt){ $(el).children(".ajax_loader").hide(); $(el).children(".button_parent").show(); } }); return false; } }[/code] [code]<form method="post" id="add_comment" action="/p_gamma/news/" onsubmit="Comment.onCommentSubmit(this, '/p_gamma/news/rq/ p_comments.php', '#ncomment_response'); return false;"> <input name="id" type="hidden" value="<? echo $get_news['id'] ?>" /> <textarea class="textarea" cols="25" name="comment" rows="4" onkeyup="Comment.remainingChars(this, event);"></textarea> <input type="submit" id="submit_comment" value="Add comment" /> </form>[/code] Is the js/jquery ok? Can i short something or make better? But the problem I've is here: [code]loadContents(targetEl, "/p_gamma/news/rq/r_latest_comments.php? id=" + $(el).children("input[name='id']").val());[/code] How to get el (in this case el is 'this' which is form) input, which name=id value? It returns me 'undefined' because i think my mistake is here: $(el).children("input[name='id']").val(), bet viss pārējais darbojas.