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.

  1. don't use input event, it's not supported in many browsers, use keyup instead, works on paste also

  2. don't mix jquery pure js, use $(this).val() instead of document.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);     }); }); 

demo

and yep, forgot # before identifier

updated demo


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

node.js - Node - Passport Auth - Authed Post Route hangs on form submission -

Does Firefox offer AppleScript support to get URL of windows? -