SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot diskhub's Avatar
    Join Date
    Jun 2004
    Location
    singapore
    Posts
    161
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question controlling two buttons in a form

    Hi i have two buttons in a form.
    1 is called Edit; the other 1 is called Delete

    when user click on Edit, i want the form to go to another page with POST.
    however if user click on Delete button, i wish to run through a script to determine whether the form should be return true or false.

    How can i achieve this.
    Following is my script:

    my form name is: order_amend
    my radio button group is: booking_grp

    Code:
    //this script is for the Delete button. I do not wish the page to be submitted before this execution. And the form should be determined by the user.
    function confirmation() {
    	var len =  document.order_amend.booking_grp.length
    	
    	var bookingid;
    	for(var i=0; i< len; i++){
    		if(document.order_amend.booking_grp[i].checked == 1)
    			bookingid = document.order_amend.booking_grp[i].value;
    	}
    	
    	var msg = "Are you sure you want to delete "+bookingid+" ?";
    	
    	var sure = confirm(msg);
    	if (sure){
    		return true;
     	}else{
    		return false;
    	}
    
    }
    </script>
    
    
    <form action="orders_amend.php" method="post" name="order_amend" target="_self">
    
    <input type="submit" name="Edit" id="button" value="Edit" onclick="test()">
    
     <input type="submit" name="Delete" id="button" value="Delete" onclick="confirmation()">
    please advise...
    I LOVE PHP!!!

  2. #2
    SitePoint Evangelist
    Join Date
    Jul 2007
    Posts
    345
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Would onclick="return confirmation()" sort it for the delete button?

  3. #3
    SitePoint Zealot diskhub's Avatar
    Join Date
    Jun 2004
    Location
    singapore
    Posts
    161
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    haha,
    thanks so much...
    small mistake...

    anyone know where i can read up more about javascript DOM for all the form elements?
    I LOVE PHP!!!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •