Click here to Skip to main content
15,886,422 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi I have a Editorfor field and i want to make this a percentage field. if i put cursor on the input field it will show the number if i remove focuse it should become % (for example put cursor and type 2 and remove focus then it should become 2%). I am trying to implement custom attribute i don't know how to implement. Can somebody please help with sample code or any other alternative.

Thanks in advance..
Posted

1 solution

Your question is a little bit confusing, once you say, you want to get the number only if the input is in hover, and then you say you want to write the '2' and then get the '2%' written. I don't understand.

However, you can do it this way, first create an HTML element,

HTML
<input type="text" value="" id="toWorkOn" />


Now handle the hover event using jQuery,

JavaScript
// upon hover, 
$('#toWorkOn').hover(function () {
   // if the element's value changes
   $(this).change(function () {
      // keep the value
      // or do whatever here.
   });
});


I hope I have answered!
 
Share this answer
 
Comments
yadlaprasad 18-Aug-14 0:28am    
Hi Afzaal, Thanks for your response. My requirment is I have input field that should only accept % values (example 2%, 0.5%, 2.4% etc..). if i type some value on input filed like for example '2' when I tab out or remove focus from the input field it should become '2%'. for input filed i am using @Html.EditorFor. Hope this is clear.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900