• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 321
  • Last Modified:

adding a confirm delete form to a page using jquery

I'm trying to Implement an event to confirm delete  using j query in the next code attached

Im trying to pop up a form that will confirm the delete.
and when delete is pressed in the form I thought of checking it by if (POST['deleteEmai'])
and there delete from the db .

the problem is I have a feeling i need to use ajax because after deleting I need the page to not show the line that was deleting so I need the page to load again

maybe Im wrong and that why I wanted an advise
 
 <form id = "popup_form " style="background-color:white; border:2px solid blue;padding:4px; width:250px; display:none; position:absolute">

                are you sure you want to delete?
                 <input type=\"submit\" value=\"Delete\" name=\"deleteEmail\" style=\"margin-right:15px\">
                  <input type=\"button\" value=\"Close\"  onclick=\"closePopup()\" />

              </form>

<td onclick = "toggleDelete()"

            style="color: red; display:none; padding: 0px 10px;"
			id="spam_{$row['id']}_body"

			>

			Mark as spam

Open in new window

0
Nura111
Asked:
Nura111
  • 10
  • 9
1 Solution
 
sammySeltzerCommented:
This is probably what you need?

 <form id = "popup_form " style="background-color:white; border:2px solid blue;padding:4px; width:250px; display:none; position:absolute">
<input type="submit" value="Delete" name="deleteEmail" style="margin-right:15px" onclick="return confirm('Are you sure you really want to delete this  record?');"  >
<input type=\"button\" value=\"Close\"  onclick=\"closePopup()\" />
</form>

Open in new window

0
 
Nura111Author Commented:
yes  but Im asking about the part whicj I need to handle the submit event in that case I need to perform an a delete form a db which is fine and reload the page wiht the new data which i think I need ajax for but im not sure
0
 
Nura111Author Commented:
and I need to show this form as a pop up window so I wanted ot know if there is anyway doing that using jquery
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Nura111Author Commented:
Also if im using <input type="submit" value="Delete" name="deleteEmail" style="margin-right:15px" onclick="return confirm('Are you sure you really want to delete this  record?');"  >

how do I check if the submit button has been pressed?
0
 
sammySeltzerCommented:
You have confused me, I am sorry but I don't know what you are asking.
0
 
Nura111Author Commented:
I dont know how to handler the return value from my php code when using
onclick="return confirm('Are you sure you really want to delete this  record?');"



normally I would check for a sumbit in my code if the form is in method post:
if POST['deleteEmail'] right??
so my question is how would I check the return value from the confirm () function
0
 
sammySeltzerCommented:
I dont know how to handler the return value from my php code when using
onclick="return confirm('Are you sure you really want to delete this  record?');"


All that onclick does is give you an alert box that says, "are you sure you really want to delete this record?

It will give you 2 buttons, one says OK (if you press it, the record you wish to delete is deleted).

The other button is says Cancel. Clicking the cancel means you don't want to delete.

Is it what you want to do? Nothing gets returned unless you wish to display a message that says, record deleted.

if $_POST(['deleteEmail']) == "deleteEmail"
{
//perform your delete operation here:

delete from your table where condition is true
}
end if
0
 
Nura111Author Commented:
ok  so if you know how its work I would like to understand that the confirm is return a value and who/what is handling the value I just dont understand how its work..

Thank you for the help!
0
 
sammySeltzerCommented:
I still don't understand what you mean by return a value.

I just explained to you what the confirm will do. It does not return a value.

Can you explain in simple terms what you are trying to do with this return value thing?

Or if you have a different kind of confirm in mind, then explain it.

I just took another look at  your form and saw that you have <input name="deleteEmail" value="Delete">

So, this should be something like:

if $_POST(['deleteEmail']) == "Delete"
{
//perform your delete operation here:

delete from your table where condition is true
}
end if
0
 
EyalCommented:
see http://jquery-howto.blogspot.com/2009/05/remove-table-row-on-user-click.html

in addition you should add confirm before the $.get... or/and combine it with sammySeltzer checks
0
 
Nura111Author Commented:
sammySeltzer:: when you use onclick =return confirm(ddjd) I thought that the return syntax mean that you using confirm return value otherwise what is that return mean??
0
 
sammySeltzerCommented:
displays an alert box  with a message the you have specified.
0
 
Nura111Author Commented:
the problem is that now when im cheking
 if (isset($_POST['spamIt'])){
//do things

}

even when the result is cancel the "confirm" email  it will "do things"
how can I check if the result from the confirm was cancel or ok?
0
 
sammySeltzerCommented:
You are still confused about what that alert box does.

If you decide to delete and you click Ok button, whatever data you wish to delete will be deleted.

It is up to you to echo that out by saying something like "record successfully deleted"

If you wish to get fancy, you indicate the record deleted, something like "record [record name or record id) successfully deleted"

If you decide to change your mind about deleting, you hit the Cancel button and nothing happens.

see screenshot of what you get when you attempt to delete and you wish to get a warning before deleting.


confirm.JPG
0
 
Nura111Author Commented:
thats the thing because that in the php script you check if somebody clicked the delete email buttin

if (isset($_POST['deleteEmail']))
{
Insert to the db
}

when I have the confirm as well it will do ehat every Im doing after the check twice I checked it in my script that is what happening.

"If you wish to get fancy, you indicate the record deleted, something like "record [record name or record id) successfully deleted""

so that is exctly what im asking how can I check form the php script what was clicked in the confirm window? the ok on cancel
0
 
sammySeltzerCommented:
Don't you have like a summary page where you have:

Delete | first name | last name, etc

Everything organized by row and unique ID

So, for example, let's say you have a row like:

Delete:<input name="firstname" value='Sammy'> row1
Delete:<input name="firstname" value='JoeBlow'> row2

If you wish to delete first row with name, Sammy then after you click delete and you are asked to confirm, then on your processing page,
you can do something like:

$myname = $_POST["firstname"];
...
...
echo " deleted $myname";

something like that.


Sorry, explain better what you mean here.

when I have the confirm as well it will do ehat every Im doing after the check twice I checked it in my script that is what happening.


I am heading out but I can check back letter.
0
 
Nura111Author Commented:
I really dont get what is not understood in my question.. exctly like you just explained to access $myname = $_POST["firstname"];

how do I access to the value that clicked when in the confirm "form"

$OkorCancel =$_POST["what to write here???"]

Thank you
0
 
sammySeltzerCommented:
$OkorCancel =$_POST["what to write here???"]
This is why I don't understand what you are asking.

There is NO value to be obtained by clicking Cancel.

I have explained this before.

When you cancel, nothing happens, nothing gets captured, just as you don't get any value by clicking Ok.

The only value you get by clicking Ok is that the onclick event is invoked and the delete action is fired.

In which case, you get the value of what is deleted.
0
 
Nura111Author Commented:
by checking :

 if (isset($_POST['deleteEmail'])){
//do things

}

even when hitting cancel on the confirm window its doing the action anyway so when pressing ok it will it twice
0
 
sammySeltzerCommented:
can you post your code so I can take a look?

There is some bug in there because cancelling an action should do nothing.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 10
  • 9
Tackle projects and never again get stuck behind a technical roadblock.
Join Now