Jump to content
alexarpad2003

javascript confirm

Recommended Posts

Posted

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 ?

Posted

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>

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...