alexarpad2003 Posted July 31, 2011 Report Posted July 31, 2011 Am javascriptu :<script type="text/javascript">function show_confirm(){var r=confirm("Sunteti sigur?");if (r==true) {return 1;}else {return 0;}}function v_submit(){ var ok=0; ok+=show_confirm(); if(ok==1) document.del.submit();}</script>Si am mai multe formuri de genul :<form name="del" method="post"> <p>Text text</p> <input type="hidden" name="nume_stire" value="au-inceput-inscrierile-pentru-bac"> <input name="sterge" type="button" value="Sterge" onclick=v_submit()> </form><form name="del" method="post"> <p>Text text</p> <input type="hidden" name="nume_stire" value="a-venit-vacanta"> <input name="sterge" type="button" value="Sterge" onclick=v_submit()> </form> generate cu php din baza mea de date.Intrebarea mea e cum pot aplica functia v_submit() la toate formurile fara a fi nevoit sa fac la fiecare form o functie separate ? Quote
not.user.friendly Posted July 31, 2011 Report Posted July 31, 2011 Poti folosi event-ul jQuery .click() si pui o clasa/id la acele butoane care vrei sa foloseasca functia ta cand se da click pe ele. Ca in exemplul de mai jos. <script src="http://code.jquery.com/jquery-latest.js"></script> <form name="del" method="post"> <p>Text text</p> <input type="hidden" name="nume_stire" value="au-inceput-inscrierile-pentru-bac"> <input name="sterge" class="functia" type="button" value="Sterge"> </form> <form name="del" method="post"> <p>Text text</p> <input type="hidden" name="nume_stire" value="a-venit-vacanta"> <input name="sterge" class="functia" type="button" value="Sterge"> </form> <script type="text/javascript"> function show_confirm() { var r=confirm('Sunteti sigur?'); if (r==true) {return 1;} else {return 0;} } $('.functia').click(function(){ var ok=0; ok+=show_confirm(); if(ok==1) document.del.submit(); }); </script> Quote