![Picture of Nick Rivers Picture of Nick Rivers](/graphics/unknown.gif)
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
/////////////