cannot pass variable value with confirmation script with type=image button

Discussion in 'JavaScript' started by ketting00, Sep 25, 2011.

  1. #1
    Hi,
    I can get the confirmation script redirected to a page I want with the script bellow, but the variables I want to carry over do not pass. How do I solve this problem?

    
    <script type="text/javascript">
    <!--
    	function confirmation() {
    		var answer = confirm("Are you sure you want to delete the item?");
    		if (answer){
    			alert("Removing the item!");
    			window.location = "delete.php";
    			return true;
    		} else {
    			alert("Some items worth keeping!");
    			return false;
    		}
    	}
    //-->
    </script>					
    <form method='post'>
    	<input type='hidden' name='id' value='<?php echo $row['id']; ?>' />
    	<input type='hidden' name='name' value='<?php echo $row['name']; ?>' />
    	<input type='image' src='images/delete.png' onclick='confirmation(); return false' title='delete item' />
    </form>
    
    Code (markup):
    Thanks so much
     
    Last edited: Sep 25, 2011
    ketting00, Sep 25, 2011 IP
  2. ketting00

    ketting00 Well-Known Member

    Messages:
    782
    Likes Received:
    28
    Best Answers:
    3
    Trophy Points:
    128
    #2
    ketting00, Sep 25, 2011 IP
  3. ketting00

    ketting00 Well-Known Member

    Messages:
    782
    Likes Received:
    28
    Best Answers:
    3
    Trophy Points:
    128
    #3
    I get it done with the post method. For those who struggle with this, use the onsubmit event to handle it.
     
    ketting00, Sep 25, 2011 IP
  4. SheetalCreation

    SheetalCreation Peon

    Messages:
    42
    Likes Received:
    1
    Best Answers:
    3
    Trophy Points:
    0
    #4
    I can't see any variable passed to caling script. You need to pass the variable while calling function itself. Let me know which variable exactly you wanted to pass, i can help you to write code for the same.

    Sheetal
     
    SheetalCreation, Sep 27, 2011 IP