Reputation: 269
I have Textboxes in UI as inside a grid . I mean to say many textboxes with the Same IDs
@Html.TextBox("Buyer Charge")
in Source code it appaers as :
<input id="Buyer_Charge" name="Buyer Charge" type="text" value="1.0000" />
Here are my queries
I'm firing an event on blur of textbox of id - "Buyer_Charge". Its firing only for the first row text box. Its not hapening for next rows of textboxes in that grid
I want to format the Text value to Currency value in("$###,###,###,##0.00")
Pls let me know the soultions for my queries
Upvotes: 0
Views: 1831
Reputation: 1987
U should change ID to class, coz id is unique.
and you can loop it with .each() method and set .focus() method to change border of text input About formatting value to currency, you can use .each() method again and use your code to set_currency.
$('.Buyer_Charge).each(function(){ set_currency });
Demo In demo I just create event blur on your text input
Upvotes: 0
Reputation: 65264
First of all, id
's should be unique in a page. That's the reason why it only fires on the first one as what you have said.
But! If you can't help it, here's a little trick.
$('[id=Buyer_Charge]').css('border', '1px solid red');
and to format your <input>
, try masked plugin.
Upvotes: 2
Reputation: 5157
my understanding is that IDs are always supposed to be unique and that in the event there are multiples of the same ID, the code will only affect the first found, which is what you're saying.
That said, something like
$(#Buyer_Charge).each(function(){ change format });
may be what you're looking for. Consider turning the IDs into classes in your html, too.
A class should define elements that act the same way where an ID should refer to a specific element.
Upvotes: 0