javascript - clearing textbox on click -
i making basic chat web app. accomplish functionality , working on user experience. learning js , jquery. want able clear input box of text click within box come in in new text/msg. i'm not sure how so. here have far.
i added line thinking accomplish intend isn't occurring.
$("form#my_msg").onclick().val("");
code:
<script type="text/javascript"> $(document).ready(function() { // connect var socket = io.connect('http://' + document.domain + ':' + location.port); // response browser socket.on('response', function(msg) { $('#log').append("<br>" + msg.data); }); // send message $('form#broadcast').submit(function(event) { socket.emit('send message', { data: "<b>" + $('#username').val() + "</b>" + " --> " + $('#my_msg').val()}); homecoming false; }); $("form#my_msg").onclick().val(""); }); </script> <body class="body"> <form id="broadcast" method="post" action="#" class="form-group"> <input type="text" id="username" placeholder="username" class="form-control"> <input class="form-control" type="text" id="my_msg" placeholder="enter message here..."> <button type="submit" class="btn tbn-default" style="background-color: #80ff80;">send</button> </form> <h2>chat</h2> <div id="log"></div> </body>
with respect comment question!
clearing textbox on every focus or click not thought chat web app.
explain details in comment saying why should not follow clearing text field on focus in such scenario.
you can script clear text on submit after calling ajax phone call send message receiver.
// send message $('form#broadcast').submit(function(event) { socket.emit('send message', { data: "<b>" + $('#username').val() + "</b>" + " --> " + $('#my_msg').val()}); $("#my_msg").val(""); homecoming false; });
javascript jquery html flask
No comments:
Post a Comment