asp.net mvc 3 - Setting focus for MVC (Html.TextBoxFor) using jquery -


i'm working on mvc project , trying set focus on this:

<td><%=html.textboxfor(de => model.emailaddress1)%></td> 

my jquery in same view near top of page:

<script type="text/javascript">     $(document).ready(function () {         $("[id$=maincontent_emailaddress1").focus();         $("#emailaddress1").focus();     }); </script> 

i've tried few combinations set focus box nothing i've tried works. can help?

you take several steps in solving problem. first of all, load html , see, weather id being rendered matches 1 provided. secondly, i'd rather suggest more rigid way capture element, or control output.

you add functional class grab element

html.textboxfor(x => x.emailaddress1, new { @class = "fhandleclass" }); 

and script

<script type="text/javascript"> //<![cdata[   $(function(){       $(".fhandleclass").focus();   }); //]]> </script> 

or directly control id

html.textboxfor(x => x.emailaddress1, new { id = "myexactid" }); 

and script

<script type="text/javascript"> //<![cdata[   $(function(){       $("#myexactid").focus();   }); //]]> </script> 

and finally, suggest switch razor view engine. better, web forms view engine designed understood designers, not friendly handwriting. razor designed being written hand.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -