1
<script runat=server language=javascript>
    function checkstatus() {
        for (count = 0; count < cntrl.value; count++) {
            if (form1.ordercheckbox[count].checked === true) {

                var accvalue = form1.ordercheckbox[count].value;
                alert(accvalue); // This gives me the exact value of checked box! How I can set this value into AMPScript variable? 

            }

        }
    }

</script>

After getting the values into Ampscript I need to add it to Data Extension using %%=InsertDE()=%%

2 Answers 2

1

All the form field values can be retrieved using RequestParameter("name") function in the AMPScript. See the RequestParameter link on the help pages.

One suggestion, since the checkbox controls handled slightly different by browsers ensure that you specify the value attribute on the <input> control in the form and then in AMPScript you can do a following check to distinguish whether or not it was selected:

IF (RequestParameter("checkbox-name") == "value") THEN
    /* case when it was selected*/
ELSE
    /* case when it was not selected */
ENDIF
0

You can't mix server-side and client-side JavaScript. SSJS is only executed on the server (much like PHP). Client-side is like jQuery.

You can default checkboxes, with SSJS, but retrieving the values of those checkboxes will have to come from a form post. Here's a brief example.

The process would be when the Request.Method == "GET", default the checkbox values. The page loads, boxes are checked or unchecked and the user submit the form. When Request.Method == "POST" then retrieve the current checkbox value from the form using Request.GetFormField("VARNAME") and insert the values into the data extension using InsertDE() in AMPScript or Add() in SSJS

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .