Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jun 2008
    Thanked 9 Times in 9 Posts

    confirm alert and checkbox validation

    hi all

    i have one form inside other form in which i have delete button and i want to apply validation on it.

    This is form code
    <form id="form1" name="form1" method="get" action="" onsubmit='return cbox();'>
    echo "<form name='del_sel' method='post'>"; 
    echo "<td valign='top' colspan='9'><input name='submit' type='submit' value='Delete Selected' onClick=\"return confirm('Are you 100% totally certain that you want to DELETE this ?')\"/>";
    echo "<input type='hidden' name='checkbox[]' value=".$row2['order_id']." />";
    echo "</td>";
    echo "</form>";

    this is validation function which checks whether one checkbox is selected or not.
    function cbox()
    var chks = document.getElementsByName('checkbox[]');
    var hasChecked = false;
    for (var i = 0; i < chks.length; i++)
    if (chks[i].checked)
    hasChecked = true;
    if (hasChecked == false)
    alert("Please select at least one.");
    return false;
    return true;
    now the problem is that cbox() function and confirm function both appears one after another. i want that if cbox() returns true means if any one of the chekbox is selected then only the confirm alert should appear otherwise it should not appear.

    Last edited by vineet; 06-22-2009 at 05:52 AM. Reason: code

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    London, England
    Thanked 2,573 Times in 2,551 Posts
    If the checkbox is hidden I don't see how the user can select it. If you change it to
    <input type='checkbox' name='checkbox[]'
    then it works fine.

    So - did anyone dare tell George Stephenson, "It's not Rocket science"?


    Posting Permissions

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