views:

447

answers:

1

What's the correct syntax for an HTML helper (in MVC2) to define an onblur handler where the textbox is generated with code like:

<%=Html.TextBox(
    "ChooseOptions.AddCount" + order.ID,
    (order.Count > 0) ?  AddCount.ToString() : "",
    new { @class = "{number: true}  small-input" }
)

thx

A: 

Add the onblur to htmlattributes

<%=Html.TextBox(
    "ChooseOptions.AddCount" + order.ID,
    (order.Count > 0) ?  AddCount.ToString() : "",
    new { @class = "{number: true}  small-input", onblur = "alert('fired')" }
) %>

Or a better way add it with jQuery

$('#ChooseOptions_AddCount' + id).onblur(function() { alert('fired'); });
gmcalab
The page uses jQuery but I haven't parsed the model values over to it in any overt way. In order to use the jQuery suggestion i'd have to do some sort of <script> jqValue = <%=serverSideValue%> </script>, right. Things are quite _that magical yet, are they?
justSteve
@justSteve - No you wouldn't need to do that. You could simply select all the inputs with the that class so... `<input class="myClassName" />``$('input.myClassName').onblur(function() { alert('fired'); } );`
gmcalab

related questions