开发者

How to check the contents of checkbox array before submit

I have a php function like this

function printSelectedMembers($id) {

    $full_name = $this->getUserName($id);
    echo '<dl>';
    echo '<dt><label for="event_show">Selected member :</label></dt>';
    echo '<input type="checkbox" name="pvtContac开发者_Python百科ts[]"  checked="checked" value="'.$id.'"/>'.$full_name;
    echo '</dl>';
}

In this I want to delete the entry if the member is already in the checkbox array ( pvtContacts[] ). How will I check the contents of the array before submitting the form ?


as in comments you cannot check fields with php, as they are checked after the form is submitted, but you can use javascript to check if checkboxes are checked.

<script type="text/javascript">
function checkForm(form) { 
    for (i=0; i<form.elements['pvtContacts[]'].length; i++) { 
        // this is where you start the checks or altering the form
        // remove (but you have to setup an unique id for each field):
        // var thisId = document.getElementById(form.elements['pvtContacts[]'][i].id);
        // thisId.parentNode.removeChild(thisId);
        if (form.elements['pvtContacts[]'][i].checked != true) { 
            // no all checkboxes are checked
            return false; 
        } 
    } 
    return true; 
}
</script>

you can modify the function to alter/delete some parts ...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜