javascript - jQuery .bind binded function not firing -
i've been searching solution while can't still code work.
i'm trying bind 'input' event. here's have far
<script type="text/javascript"> $(document).ready(function () { $('#txtrtmuserid').bind('keyup', function () { var inputvalue = $('#txtrtmuserid').val(); inputvalue = inputvalue.replace(/-/g, ""); var outputval = ""; var inputlength = inputvalue.length; (var = 0; < inputlength; i++) { outputval += inputvalue.charat(i); if (i == 7) { outputval += "-"; } if (i == 11) { outputval += "-"; } if (i == 15) { outputval += "-"; } if (i == 19) { outputval += "-"; } } $('#txtrtmuserid').val(outputval); }); });
here's textbox control:
<input type="text" id="txtuserid" value = "@consumerid" tabindex="20" style="width: 250px;" maxlength="36"/>
update:
i got working on paste event. see updated script above. 1 problem though, when paste valid guid, press right arrow (to make corrections) brings me end of text in textbox. must enable user make corrections.
don't use
input
event, it's not supported in many browsers, usekeyup
instead, works on paste alsodon't mix jquery pure js, use
$(this).val()
instead ofdocument.getelementbyid("txtuserid").value
example:
$(document).ready(function() { $('#txtuserid').bind('keyup', function() { var inputvalue = $(this).val(); inputvalue = inputvalue.replace(/-/g, ""); // , other replacements here, e.g. // inputvalue = inputvalue.replace(/(^.{7}|.{4})/g, "$1-"); $(this).val(inputvalue); }); });
and yep, forgot #
before identifier
Comments
Post a Comment