vendredi 6 décembre 2019

Coldfusion: I need to change a struct value when a checkbox is checked

The code dynamically creates purchase orders with checkboxes as well as builds a struct with the key being the PO number and the value is false. I need to switch the struct value to true when the checkbox is checked.

<!--- declare an array to hold the structs. --->
<cfset checkedPOsArray = ArrayNew(1)>

<!--- dynamically create the po checkboxes --->
<cfloop query="someQuery">
    <input type="checkbox" name="po_number_#someQuery.PoNumber#" onClick="changeStructValue(#someQuery.PoNumber#)" value="1" />

    <!--- declare a variable to hold each po number. --->
    <cfset thisPONumber = "#someQuery.po_number#">

    <!--- build a struct to hold the booleen values. --->
    <cfset thisPO_st = StructNew()>
    <cfset thisPO_st.isChecked_[variables.thisPONumber] = false>

    <!--- append the structs to the array --->                      
    <cfset ArrayAppend(variables.checkedPOsArray, thisPO_st)>
</cfloop>

<script type="text/javascript">

    function changeStructValue(poNum) {
        // grab the specific input that was checked.
        var checkbox = document.querySelector("input[name=po_number_" + poNum + "]");

        if(checkbox.checked) 
        {   
            // set the value of the ischecked struct field to true.
            document.selectedPlantsArray.indexOf(thisPO_st.isChecked_[poNum]).value = true;
        };
    };
</script>



Aucun commentaire:

Enregistrer un commentaire