954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

javascript+php

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.

heliumgas
Newbie Poster
11 posts since Mar 2007
Reputation Points: 10
Solved Threads: 0
 

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);" />

~s.o.s~
Failure as a human
Administrator
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
 

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????

heliumgas
Newbie Poster
11 posts since Mar 2007
Reputation Points: 10
Solved Threads: 0
 

You forgot to open the

~s.o.s~
Failure as a human
Administrator
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
 

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>
heliumgas
Newbie Poster
11 posts since Mar 2007
Reputation Points: 10
Solved Threads: 0
 

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.

~s.o.s~
Failure as a human
Administrator
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
 

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.

MidiMagic
Nearly a Senior Poster
3,319 posts since Jan 2007
Reputation Points: 730
Solved Threads: 182
 

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

heliumgas
Newbie Poster
11 posts since Mar 2007
Reputation Points: 10
Solved Threads: 0
 

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...

heliumgas
Newbie Poster
11 posts since Mar 2007
Reputation Points: 10
Solved Threads: 0
 

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

~s.o.s~
Failure as a human
Administrator
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You