Solved

adding a confirm delete form to a page using jquery

Posted on 2011-09-20
20
313 Views
Last Modified: 2012-06-22
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
Comment
Question by:Nura111
  • 10
  • 9
20 Comments
 
LVL 28

Accepted Solution

by:
sammySeltzer earned 500 total points
ID: 36570234
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
 

Author Comment

by:Nura111
ID: 36570263
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
 

Author Comment

by:Nura111
ID: 36570279
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
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 

Author Comment

by:Nura111
ID: 36570606
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
 
LVL 28

Expert Comment

by:sammySeltzer
ID: 36570642
You have confused me, I am sorry but I don't know what you are asking.
0
 

Author Comment

by:Nura111
ID: 36570655
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
 
LVL 28

Expert Comment

by:sammySeltzer
ID: 36570691
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
 

Author Comment

by:Nura111
ID: 36570717
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
 
LVL 28

Expert Comment

by:sammySeltzer
ID: 36571177
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
 
LVL 15

Expert Comment

by:Eyal
ID: 36572872
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
 

Author Comment

by:Nura111
ID: 36574884
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
 
LVL 28

Expert Comment

by:sammySeltzer
ID: 36574908
displays an alert box  with a message the you have specified.
0
 

Author Comment

by:Nura111
ID: 36576244
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
 
LVL 28

Expert Comment

by:sammySeltzer
ID: 36576451
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
 

Author Comment

by:Nura111
ID: 36576516
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
 
LVL 28

Expert Comment

by:sammySeltzer
ID: 36576903
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
 

Author Comment

by:Nura111
ID: 36576937
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
 
LVL 28

Expert Comment

by:sammySeltzer
ID: 36577376
$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
 

Author Comment

by:Nura111
ID: 36577385
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
 
LVL 28

Expert Comment

by:sammySeltzer
ID: 36577410
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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question