www.webdeveloper.com
Results 1 to 3 of 3

Thread: Control confrim delete

Hybrid View

  1. #1
    Join Date
    Oct 2012
    Location
    istanbul
    Posts
    64

    Control confrim delete

    Hello,

    The alert() musn't display, if any checkbox(s) isn't selected.
    How can I do this?

    PHP Code:
    <script language="javascript">
    function confirmDel() {
     var agree=confirm("Are you sure you want to delete rows?!");
     if (agree) {
      return true ; }
     else {
      return false ;}
    }
    </script>

    <input type="checkbox" name="name[]" value="<?=$id?>">
    <input type="checkbox" name="name[]" value="<?=$id?>">
    <input type="checkbox" name="name[]" value="<?=$id?>">
    <input type="checkbox" name="name[]" value="<?=$id?>">
    <input type="checkbox" name="name[]" value="<?=$id?>">

    <input type="submit" onclick="return confirmDel();" />
    Thanks in advance

  2. #2
    Join Date
    Mar 2009
    Posts
    452
    Code:
    <script language="javascript">
    function confirmDel() {
    	var inputElems = document.getElementsByTagName('input'), count = 0;
    	for (var i=0; i<inputElems.length; i++) {
    		if (inputElems[i].type === 'checkbox' && inputElems[i].checked === true) {
    			count++;
    		}
    	}
    	
    	if (count<1){alert('select atleast one item');return false;}
    	 var agree=confirm("Are you sure you want to delete rows?!");
    	 if (agree) {
    	  return true ; }
    	 else {
    	  return false ;}
    }
    </script>
    
    <input type="checkbox" name="name[]" value="<?=$id?>">
    <input type="checkbox" name="name[]" value="<?=$id?>">
    <input type="checkbox" name="name[]" value="<?=$id?>">
    <input type="checkbox" name="name[]" value="<?=$id?>">
    <input type="checkbox" name="name[]" value="<?=$id?>">
    
    <input type="submit" onclick="return confirmDel();" />

  3. #3
    Join Date
    Oct 2012
    Location
    istanbul
    Posts
    64
    Excellent, thank you so very much

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles