hello.
i would like to know how i can use the message box ok/cancel to confirm the delete os data in the database. as javascript is clientside and php in server side hw i can do it? how i can send it to php undestand that is to del the data? i'm just getting started in java so it's dificult for me. sorry for my english but as you could probably seen i´m not one.

Recommended Answers

All 9 Replies

Submit the form data to the php script only if the user clicks on OK.

function checkSubmission(form)
{
    var ans = confirm("Are you sure you want to delete the row?");
    if(ans)
    {
        //perform validation
        form.submit();
    }
}

Call this function on the onclick event of the submit button and pass to it, the form object. Something like: <input type="button" value="Submit" onclick="checkSubmission(this.form);" />

ok i solve my problem but now i have another one
when i try to use two message box in the same page it dosen't work only one works.

<form method="post" onSubmit="return validar_apagar();" action="dest_agen.php">
.....
<input type="hidden" id="xpto" value="editar"/>              
<input id="botao" type="submit" name="aFazer" value="Editar"/>
<input id="botao" onClick="document.getElementById('xpto').value='apagar';" type="submit" name="aFazer" value="Eliminar" />
</form>

<script>
function validar_apagar()
{
    if (document.getElementById('xpto').value=='apagar')
        return confirm('Deseja apagar a Noticia?');
}
</script>

(.......)
<form method="post" onSubmit="return validar_apagar2();" action="dest_agen.php">
....
<input type="hidden" id="xpto2" value="editar"/>      
<input id="botao2" type="submit"  name="aFazer2" value="Editar"/>
<input id="botao2" onClick="document.getElementById('xpto2').value='apagar';" type="submit" name="aFazer2" value="Eliminar_Evento" />
</form>
function validar_apagar2()
{
    if (document.getElementById('xpto2').value=='apagar')
        return confirm('Deseja apagar o Evento?');
}

</script>

as i said before only the fisrt works i can´t put the second form working can anybody help me????

You forgot to open the <script> tag for the second function i.e. put a script tag after the second </form>.

i´m sory for my mistake but i forget to pass that i have it on my page that srcipt but it doesn´t work....

<form method="post" onSubmit="return validar_apagar();" action="dest_agen.php">
.....
<input type="hidden" id="xpto" value="editar"/>              
<input id="botao" type="submit" name="aFazer" value="Editar"/>
<input id="botao" onClick="document.getElementById('xpto').value='apagar';" type="submit" name="aFazer" value="Eliminar" />
</form>

<script>
function validar_apagar()
{
    if (document.getElementById('xpto').value=='apagar')
        return confirm('Deseja apagar a Noticia?');
}
</script>

(.......)
<form method="post" onSubmit="return validar_apagar2();" action="dest_agen.php">
....
<input type="hidden" id="xpto2" value="editar"/>      
<input id="botao2" type="submit"  name="aFazer2" value="Editar"/>
<input id="botao2" onClick="document.getElementById('xpto2').value='apagar';" type="submit" name="aFazer2" value="Eliminar_Evento" />
</form>
<script>
function validar_apagar2()
{
    if (document.getElementById('xpto2').value=='apagar')
        return confirm('Deseja apagar o Evento?');
}

</script>

You need to be more precise when you say its not working. You either need to paste a working example here or try to put a lot of alert statements here and there in your code to see which part is creating problems for you.

I seem to remember that you can have only one set of script tags in the body. Put both functions in the same script tag pair.

ok i put both script in one tag pair and it doesn´t work...

to be more precise the second form when i prees the button eliminar_evento it doesn´t show me the message box that is the only problem...

You must have made changes to your original code. Post the most recent, working code as it is.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.