0

Maybe it's basic, but I simply can't figure this out. I have a cloudpage which I would like to use as a preference center, and therefore I need to retrieve the values of checkboxes. True/False = checked/unchecked.

I have defined all fields in the top of the page with AMPscript, example:

%%[
  SET @Id = QueryParameter('id')
  SET @Rows = LookupRows('Kontakter','Customer ID',@Id)
  IF ROWCOUNT(@Rows) > 0 THEN
SET @vvs = FIELD(ROW(@Rows,1),'interesser_vvs_inst__c')
 ENDIF
  ]%%

And in my smart-capture this is what I have inserted:

<div class="smartcapture-controls"><div class="sc-formfield-label"></div>
<div class="sc-formfield-input-wrapper">

  <div class="sc-formfield-input">
%%[IF @vvs == True THEN]%%
      <input name="vvs" value="Y" type="checkbox" checked=""> 
%%[Else]%%
      <input name="vvs" value="Y" type="checkbox"> 
%%[ENDIF]%%
  </div></div></div>

Is there someone who can point me in the right direction, or is this the way to do it ?

Best Regards, Martin

0
3

Given that the @vvs variable will have the values of TRUE/FALSE, you could do the following:

%%[
  SET @Id = QueryParameter('id')
  SET @Rows = LookupRows('Kontakter','Customer ID',@Id)
  IF ROWCOUNT(@Rows) > 0 THEN
  SET @vvs = FIELD(ROW(@Rows,1),'interesser_vvs_inst__c')
    IF @vvs == TRUE THEN
    SET @checked = "checked"
    ELSE    
    SET @checked = ""
    ENDIF
  ENDIF
 ]%%


<div class="smartcapture-controls"><div class="sc-formfield-label"></div>
<div class="sc-formfield-input-wrapper">

<div class="sc-formfield-input">
<input name="vvs" value="Y" type="checkbox" %%=v(@checked)=%%> 

</div></div></div>
7
  • Nice clean solution Zuzannamj Oct 14 '19 at 13:53
  • @zuzannamj, thanks for the answer! It seems that my cloudpage dont want to publish, so I must have done something wrong. However I see your point, and understand what your code does! Thank you:) Oct 15 '19 at 12:51
  • Glad I could help! Please remember to accept the answer :)
    – zuzannamj
    Oct 15 '19 at 13:52
  • Hmm... It sets false values to checked as well? Oct 16 '19 at 20:06
  • 1
    Figured it out! perfect:) Oct 17 '19 at 18:52

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.