PHP Classes

Another Confirmation Popup Question

Recommend this page to a friend!

      PHP Forms Class with HTML Generator and JavaScript Validation  >  PHP Forms Class with HTML Generator and JavaScript Validation package blog  >  Locating addresses on...  >  All threads  >  Another Confirmation Popup Question  >  (Un) Subscribe thread alerts  
Subject:Another Confirmation Popup Question
Summary:Trying to solve a confirmation pop up issue...
Messages:4
Author:Nick Rivers
Date:2007-04-12 21:16:33
Update:2007-04-12 23:40:46
 

  1. Another Confirmation Popup Question   Reply   Report abuse  
Picture of Nick Rivers Nick Rivers - 2007-04-12 21:16:33
Hello. I've spent way too much time playing with this, and thought I'd try my luck here. Sorry if this may sound a bit confusing...I'll clarify if needed.

I'm trying to call a server side jscript function that creates a confirmation pop up, then redirects to either a url that contains the variable to delete a record in my db. (i.e. http://mysite/journal/username/delete=32) OR if cancel is clicked, to just return to the page the user started from. Deleting a record this way minus the pop up confirmation normally works fine...

First, I'm fetching an array of data about the records (blogs in this case). Then in a while() loop, I'm displaying the rows of data and creating an input button to allow the user to delete the record(blog) from the db if they wish, following an 'ok' click in the pop up confirmation box. (the input button contains a value which contains PHP variables determined by the blog_id number and username.

Putting this input button in a form and doing an onSubmit() calls the jscript confirmation pop up function, but then doesn't do much when either button is clicked and the resulting window.location value ends with something like ?x=9y=12.

I can sort of get this to work by not using any FORM tags and just using an INPUT button/image to set an ID and dynamic value which is used by the jscript function to determine the correct url & variable to delete the record.

The problem with that is, that it only does this for the most recent record. Any 'delete button' input values for additional blogs listed don't contain a blog_id value to be deleted and the resulting window.location returns the delete variable being 'undefined'. I'm sure this has something to do with the while() loop in my PHP.

With so little code involved to do this, I'm sure I'm missing something. Any help would be awesome. The snip of code I'm referring to is pasted below.

Thanks,
Nick


/////Javascript Function for Confirmation pop up from a jscript file////
function go_there()
{
var where_to= confirm("Are you sure you want to delete this blog?");
if (where_to== true)
{
window.location=delVal.value;
}
else
{
window.location="#";
}
}

////////PHP Variable containing the form - this is in a while loop////

while($fetching->array = $row) {
//do some other stuff

$del_html2 = '<form onSubmit="return go_there();">'.
'<input type="image" src="/images/delete.gif" align="left" alt="delete blog" id="delVal" VALUE=\"mysite.com/@journal/'.$this->user_name.'/delete='.$row[id].'"></form>';

//create the html wrapper and call the $del_html2 variable

/////////////

  2. Re: Another Confirmation Popup Question   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2007-04-12 21:58:32 - In reply to message 1 from Nick Rivers
Why don't you just have a delete button for each row and use different names for the button to include the row id, so you can figure which row the user wants to delete?

  3. Re: Another Confirmation Popup Question   Reply   Report abuse  
Picture of Nick Rivers Nick Rivers - 2007-04-12 22:48:32 - In reply to message 2 from Manuel Lemos
Thanks for the quick help!

I didn't think I could use different names, since the code that generates each delete button exists once in that same while loop. I guess the name could be dynamically generated by a 'for each' loop if that's what you mean, but I may be misunderstanding you.

  4. Re: Another Confirmation Popup Question   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2007-04-12 23:40:46 - In reply to message 3 from Nick Rivers
Right, you can add and outpu new submit inputs in the loop with different names.