Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

How to call js function with string parameter on button?

Hello! I want to generate this code with Volt:

<input type="submit" value="Add" class="btn btn-primary btn-sm" onclick="oddCheck('cost')" />

I write this code:

{{ submit_button("Добавить","class":"btn btn-primary btn-sm","onclick":"oddCheck('cost')") }}

but I get

<input type="submit" value="Добавить" class="btn btn-primary btn-sm" onclick="oddCheck(&#039;cost&#039;)" />

Please, tell me how to transfer a string parameter to the function.

Can't you bind your event with javascript ? This is bad to do like that. I suggest to you to use the form submit event if you want to add a check


I think you have enabled Volt autoescape. Try like this:

{% autoescape false %}
{{ submit_button("Добавить", "class":"btn btn-primary btn-sm", "onclick": "alert('cost')") }}
{% endautoescape %}