PDA

View Full Version : Javascript Help...



kylew
07-20-2007, 06:28 AM
I am new to Javascript and need help writing a function. The script is supposed to prompt the user with a "confirm or cancel" dialog when they attempt to delete a post from the MySQL database.

I am using PHP to send the script the unique post id, so it know what post to delete. Everything seems to be working, except I am totally lost when it comes to referencing the id variable within the Javascript. Specifically, I need to append the sent post id to the end of the "window.location" URL. Here is the Javascript and PHP I am using:

/* ----- JAVASCRIPT CODE ------- */
<script type="text/javascript">
function confirmAction(id) {
var x=confirm("You cannot undo this action. Are you sure you want to continue?")
if (x == true) {
window.location="about.php&action=delete&id=".id.""
}
}
</script>

/* ----- PHP CODE ------- */
// SHOW THE POSSIBLE POSTS TO DELETE
$query = 'SELECT * FROM `posts`';
$result = mysql_query($query);
while ($row = mysql_fetch_assoc($result)) {
echo "<a onclick=\"confirmAction(".$row['post_id'].")\">delete</a>";
} // END WHILE
________
PORTABLE SIZE TRAVEL HERBAL VAPORIZER (http://www.vaporshop.com)

areidmtm
07-20-2007, 09:09 AM
You cant split strings like you do in PHP with " . . " You'd use " + + "



<script type="text/javascript">
function confirmAction(id) {
var x=confirm("You cannot undo this action. Are you sure you want to continue?")
if (x == true) {
window.location="about.php&action=delete&id=" + id;
}
}
</script>


Then on your PHP page that deletes the row from MySQL, you would use the $_GET['id'] variable in the MySQL delete statement.

kylew
08-22-2007, 12:04 AM
I guess I'm a little late here, but thanks for the help! Much appreciated.
________
****tube.Om (http://www.****tube.com/)