PDA

View Full Version : Variables won't pass to function



peachsoda03
08-15-2007, 01:24 AM
Hello all. ^__^

I am trying to create a form that will allow a user to delete one of many records on a table, which displays the data dynamically. I'd like to have a pop up window confirm that the user does indeed wish to delete the record, but I'm having trouble with the javascript function I wrote. When I DO NOT include any variables in my submit button, the function works fine, but when I do, I receive an error saying the variable is undefined. Here is my function:



<script language="javascript" type="text/javascript">
function ask(productID) {
var answer = confirm("Are you sure you wish to remove this product?");
if (answer)
window.location.href="removeProduct.php?id=" + productID;
}
</script>


Here is the code that DOES work, but isn't what I need:



<input type='button' value='Remove' onClick='ask();'>


This is what I need to have, but I receive an error (variable undefined) in doing so (where $row["id"] is generated dynamically with PHP):

<input type='button' value='Remove' onClick='ask(" . $row["id"] . ");'>

I've been pouring over the internet for hours trying to find a solution but have been unable to find one. Any help is much appreciated! =D