We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

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



93.7k
Accepted
answer

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

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