munish
munish

Reputation: 1

selecting text of textbox on focus

Hi I have added some format on textbox like $0.00 now what i wants is to remove the format on focus and then select the value of text box code is :

$("#controlId").focus(function(){
   $(this).val(this.val().replace(/\$/g, ''));
   $(this).select();
});

this is working fine in IE and firefox but not in Google Chrome.

Can some body suggest me what should i do for this?

Upvotes: 0

Views: 237

Answers (1)

Nick Craver
Nick Craver

Reputation: 630529

.val() is a jQuery function, so it should look like this:

$("#controlId").focus(function(){
   $(this).val($(this).val().replace(/\$/g, ''));
   $(this).select();
});

Or a bit more concise/chained:

$("#controlId").focus(function(){
   $(this).val(function(i, v) { return v.replace(/\$/g, ''); }).select();
});

Upvotes: 1

Related Questions