Hi Daniweb,
I have a checkbox that is dynamically generated using php using inputs on previous pages.

<form name=partselect action="JavaScript:checkmate()" method="post">
<table>
    <?php
    while(oci_fetch($stmtgp)){
        $idpart = oci_result($stmtgp, "PART_ID");
        $stmtparts = oci_parse($conn, "select * from PARTS where PARTID='".$idpart."'");
        $execparts = oci_execute($stmtparts);
        if(!$execparts){
            echo 'unable to fetch part';
        }

        oci_fetch($stmtparts);

        $tpartcost = oci_result($stmtgp, "PART_COST")+oci_result($stmtparts, "PARTLABOURCOST");
        echo '<tr>
                <td>'.oci_result($stmtparts, "PARTNAME").'</td>';
        echo '  <td>'.$tpartcost.'</td>';
        echo '  <td><input type=checkbox name=parts value='.$idpart.'>';
        echo '</tr>';    
    }       
    ?>
    <tr>
        <td></td>
        <td></td>
        <td><input type=Submit value="Confirm">   </td>
    </tr>
</table>
</form>

I want the results of this checkbox to be passed onto the next php file, where the values that were checked shall be entered into the database. However, I first want to check to make sure that the checkbox is not empty. For this to be implemented, I gathered, the checkbox would have to pass through javascript and once it was deemed full enough, it would be forwarded to the php page. So I wrote the javascript code

<script type="text/javascript">
function checkmate(){
    var partsvar = document.partselect.parts;

    var isempty = true;
    var j = 0;
    for(i = 0; i<partsvar.length; i++){
        if(partsvar[i].checked){
            isempty = false;
        }
    }
    if(isempty == false){
        var test = 
        window.location.href = "savepartchange.php?w1="+partsvar;
        //alert(partsvar[0].value);
    }
    else if(isempty == true){
        alert("you didnt check anything");
    }
}

However this is where I am at a loss. I dont know how to send and recieve such arrays between javascript and php. Could someone guide me on what to do here?

Member Avatar for iamthwee

You don't need javascript to do this. Additionally, the user could disable javascript.

You should be able to validate a check box with php alone.

Codeigniter has a very handy validate check box method.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.