1

I have a checkbox in the page. It should be checked if the original value is True. I'm trying to implement ampscript for this, but it fails. Even it doeesn't show in the Preview.

I debugged, the value of @industry_news is displayed as true but the checkbox is not checked by default.

<label>
    <input name="industry-news" %%[ IF @industry_news == 'true' THEN ]%%checked%%[ ENDIF ]%% type="checkbox" value="Y" /> 
    Subscribe to Industry 
</label>

@industry_news is derived from the LookUpRows and set like below.

SET @industry_news = Field(@row,"Industry_News")
2

As mentioned in this post Using Ampscript to pre-fill form, check box ampscript is not working inside checkbox element when building the landing page with the "new" content builder interface via cloud pages.

The same code works when you build the Cloud page using Classic Editor--Code View option.

But if you still like to use the Content builder interface for your cloud page, you can dynamically set the checkbox checked property this way. This still works.

  %%[IF @industry_news == True THEN]%%
      <input name="industry-news" value="Y" type="checkbox" checked/> 
      %%[Else]%%
      <input name="industry-news" value="Y" type="checkbox" /> 
      %%[ENDIF]%%
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.