Pre-checked checkbox landing page | Community
Skip to main content
Level 2
March 5, 2024
Solved

Pre-checked checkbox landing page

  • March 5, 2024
  • 1 reply
  • 727 views

Hi

 

I'm creating a landing page for unsubscribe and what it shou;d do:

When opening the landing page, the checkbox for the option 'unsubscribe' should be automatically checked so that the user does not have to do this anymore. I'm trying to get this result with a script, but it's not working.

 

Script:

<script>

window.addEventListener('lpRuntimeReady',function(e){
init(e.detail)
}

function init(lpRuntime){
window.getElementByTagName('acr-form-checkbox-4').checked = true;
})

</script>

 

I'm adding this at the top of my landing page with an html content. Can someone help me and let me know what I'm doing wrong?

 

Thank you!

Kr

Lara

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by siljkla

In the mean time my colleague found the solution.

New code:

<script>
window.addEventListener('lpRuntimeReady',function(e) {
init(e.detail)
});

function init(lpRuntime) {
console.log('check unsubscribe checkbox');
document.getElementsByName('acr-form-checkbox-4')[0].checked = true;
}

</script>

1 reply

Anuhya-Y
Community Advisor
Community Advisor
March 6, 2024

@siljkla  try this code

<script>

// Get the checkbox element

var checkbox = document.getElementsByName("acr-form-checkbox-4");

// Check the checkbox

checkbox.checked = true;

</script>

 

siljklaAuthorAccepted solution
Level 2
March 7, 2024

In the mean time my colleague found the solution.

New code:

<script>
window.addEventListener('lpRuntimeReady',function(e) {
init(e.detail)
});

function init(lpRuntime) {
console.log('check unsubscribe checkbox');
document.getElementsByName('acr-form-checkbox-4')[0].checked = true;
}

</script>