Using shortcode to implement Javascript in Elementor

Objective:
To redirect users to different pages after they submit a form in Elementor. The redirection will be based on a javascript variable that is stored. I have given the submit button an ID called submitbutt.

Implementation:
For the Form in Elementor, I have selected the Actions after submit to Redirect. Also in the Redirect section, I had selected the to Shortcode option and made reference to my shortcode [elementor-template id=”1343″].

The shortcode

It is a HTML that includes a javascript and it looks like this.

<script type=”text/javascript”>
document.getElementById(‘submitbutt’).onclick = function() {
if (localStorage.getItem(‘pagex’) === ‘page_1’) {
window.location = ‘https://www.website.com/error/?1’;
}
else if (localStorage.getItem(‘pagex’) === ‘page_2’) {
window.location = ‘https://www.website.com/error/?2’;
}
else {
window.location = ‘https://www.website.com/error/’;
}
};

</script>

Problem: After users hit the submit button, no redirect occurs.

Read more here:: Using shortcode to implement Javascript in Elementor

Leave a Reply

Your email address will not be published. Required fields are marked *