Streaming live at 10am (PST)

How to change the btn code in Webflow interface?


#1

Hello!
I have a button code (in the code after Export):

I need to insert code between <input type = “submit” and value = "Get advice"

This code: onclick = "ym (12345678, ‘reachGoal’, ‘ready-btn-ru’); return true;"

How to do it in Webflow interface?

Otherwise, I have to edit a lot of code after Export.


#2

You could use a custom code embed to create a form with this submit button.

Otherwise you could give your submit button an ID within Webflow, then attach a click event listener to it to trigger your method:

document.getElementById('submitButton').addEventListener('click', function() {
    ym(12345678, ‘reachGoal’, ‘ready-btn-ru’); 
    return true;
});

Although the default Webflow form behavior may cause problems. If you can give some more context I might be able to make a better suggestion.


#3

Thank you for trying to understand and help. But unfortunately, I don’t know how to implement your idea.


#4

How and where should I put this code?


#5

You would wrap it in a script tag and put it in the footer code section of the appropriate page.

<script>
    document.getElementById('submitButton').addEventListener('click', function() {
        ym(12345678, ‘reachGoal’, ‘ready-btn-ru’); 
        return true;
    });
</script>

But I don’t know the context of what you’re doing, so if you could explain this I might be able to make a better suggestion. Are you using a Webflow form or a custom 3rd party form?


#6

I set up a goal for the metric. In order for the metrics system to read the goal achievement (the goal is to click a button), it is necessary to set a JavaScript event. Place the specified code in the button code line.

<input type = “submit” value = “Get advice” – This is the line after export. I need to put this code in between – onclick = "ym (12345678, ‘reachGoal’, ‘ready-btn-ru’); return true;"


#7

I put your code in HTML Embed, but it didn’t help. I watched the code after publication.
ID buton is submitButton.


#8

The example you have is of using an inline JavaScript function within a submit input element. The only way to do this with Webflow (as far as I’m aware) is to use a custom code embed and write your own HTML form.

Another way to trigger a JavaScript function from a button click is to use JavaScript to attach a click event listener to it. This is what I showed in my example above.

Using the method I showed will not result in the HTML submit input element showing an “onclick” attribute.