Bootstrap - Set textbox value on modal window
jquery, twitter-bootstrap
Solution
you need to encase the code inside `DOM ready event` if your script is in the header section.
$(function() {
$('#myModal').bind('show',function(){
alert('howdy');
$("#nome").val('bosta');
});
});
Problem
I've tried to bind the event 'show' in my modal but nothing happens when it's shown. Here's the code that was supposed to work. The alert is not beeing displayed. ``` <script type="text/javascript" charset="utf-8"> $('#myModal').bind('show',function() { alert('howdy'); $(".modal-body #nome").val('bosta'); }); </script> ``` Modal window code: ``` <div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h3 id="myModalLabel">Minha Conta</h3> </div> <div class="modal-body"> <form class="form-horizontal" id="mConta"> <div class="control-group"> <label class="control-label">Nome</label> <div class="controls"> <input id="nome" name="nome" type="text" placeholder="" class="input-xlarge" required=""> </div> </div> </div> </form> <div class="modal-footer"> <button class="btn" data-dismiss="modal" aria-hidden="true">Cancelar</button> <button type="submit" class="btn btn-primary">Salvar</button> </div> </div> ```