Forum Moderators: open

Message Too Old, No Replies

Function not passing form data

noob needs help

         

willybfriendly

8:10 pm on Jan 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Apologies, but I am pathetic with js. I am trying to include a confirm box in a form being processed by a php script. I am using this:

function ConfirmChoice()
{
answer = confirm("This will delete all data relating to this animal from the data base! This is irreversible. Are you sure you want to continue?")
if (answer!=0)
{
location = "path/to/php/script"
}
}

<form action="path/to/php/script" method="post" onSubmit=" ConfirmChoice(); return false;">
<input type="hidden" name="ds" value="delete">
<input type="hidden" name="itemID" value="<? $itemID?>">
<button type="submit">Delete</button></form>

My warning box pops up as expected, but when I click "OK" it appears that my post values are not being passed on to the script

Any direction to the solution would be greatly appreciated.

WBF

adni18

8:51 pm on Jan 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



if (answer!=0)

This will do:

if (answer)

adni18

8:52 pm on Jan 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



additionally, location in

location = "path/to/php/script"

should be window.location. Also, there are a couple other things. Here is a revised code for you:

<script language="javascript" type="text/javascript">
function ConfirmChoice(adr)
{
answer = confirm("This will delete all data relating to this animal from the data base! This is irreversible. Are you sure you want to continue?")
if(answer)
{
adr.submit()
}
}
</script>

<form action="path/to/php/script.php" method="post" onSubmit="ConfirmChoice(this); return false;">
<input type="hidden" name="ds" value="delete">
<input type="hidden" name="itemID" value="<? $itemID?>">
<button type="submit">Delete</button></form>

willybfriendly

9:13 pm on Jan 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks. We are making progress now :)

WBF

rocknbil

5:02 pm on Jan 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is the real deal --> adr.submit()

Your original function ended with

location = "path/to/php/script"

So it was just setting the address to that, not submitting the form.