Rene Rene - 4 months ago 25
Javascript Question

Handlebars form submit does not work

I have a form that within a handlebars put the submit does not work, I have to do? Can anyone help?

<script id="chat-window-template" type="text/x-handlebars-template">
<a href="#" class="close"><i class="fa fa-times"></i></a>
<a href="#">
<span class="pull-left">
<img src="{{ user_image }}" width="40">
<span class="contact-name">{{user}}</span>
<div class="panel-body" id="chat-bill">
<form id="messageForm">
<input id="nameInput" type="hidden" class="input-medium" value="Macbook" />
<input id="messageInput" type="text" class="form-control" placeholder="Digite uma mensagem..." />
<input type="submit" value="Send" />

$("#messageForm").submit( function() {alert();});


Perhaps handler is attached before Dom is compiled, try listening t body events, and filtering by selector, should listen to Dom nodes added in future too...

$(document.body).on("submit", "#messageForm", function() {alert();});