Input type Checkbox attribute Checked is not set on load in ampscript

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")

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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]%%


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x