0

I have a JQuery Ready function

 $(document).ready(function () {
   $('#<%= txtBlockAmount.ClientID %>').keyup(function (e) {            
   $(this).val(addCommasOnKeyPress($('#<%= txtBlockAmount.ClientID %>').val()));
  });

});


function addCommasOnKeyPress(nStr) {
    nStr = nStr.replace(/\,/g, '')
    nStr += '';
    var x = nStr.split('.');
    var x1 = x[0];
    var x2 = x.length > 1 ? '.' + x[1] : '';
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(x1)) {
        x1 = x1.replace(rgx, '$1' + ',' + '$2');
    }
    return x1 + x2;
}

it works nice on the page load. It has some textbox. It has also Dropdown List. When I want to Load Previous Value by Selected DropDown Change then it doesn't work. Have Anybody known?? Please Reply.

Jewel

25
  • 3
    This might be a problem with delegation. Take a look at on()
    – elclanrs
    Jan 9, 2013 at 7:04
  • please, show your HTML code
    – Nour Berro
    Jan 9, 2013 at 7:05
  • 3
    What is TextBox ? It's not an HTML tag, if it's a class use $('.TextBox'), if it's an id use $('#TextBox')
    – wakooka
    Jan 9, 2013 at 7:06
  • I am new to JQuery. Please tell what have to do... Jan 9, 2013 at 7:06
  • 1
    @Jewel please edit your question with the code that you put in the comments, that's really hard to read.
    – wakooka
    Jan 9, 2013 at 7:19

2 Answers 2

0

Probably, its loosing the keyup event after postback. The best bet would be to bind it in .cs page_load method, something like

txtBlockAmount.Attributes.Add("onKeyUp", "javascript:onkeyupmethod()"); 

Your js function will look like

function onkeyupmethod()
{ 
$('#<%=txtBlockAmount.ClientID'%>).val(addCommasOnKeyPress($('#<%= txtBlockAmount.ClientID %>').val();
}
0
0

Try This:

var textb = $('#<%=TextBox.ClientID'%>);
$(document).ready(function () {
            textb.keyup(function (e) {            
                this.val(CustomizeFunction(textb.val()));
            });

        });
3
  • You put your jQuery object in a variable and you then use $ sign to wrap it again. You could just do textb.keyup(function (e) {
    – wakooka
    Jan 9, 2013 at 7:25
  • its worked first time on page load. so if wrong then what was it worked? Jan 9, 2013 at 7:32
  • your code does not work. Thanks for appreciation. Just added an attribute in .vb which create the function from script side Jan 9, 2013 at 7:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.