Using jquery to generate a Slug from Title (on lost focus)
I want to use jquery to create a request to a controller action posting Title and getting back Slug. This needs to happen 开发者_开发技巧when user enters a title into a Title textbox on the form and then uses tab or enter to move to the next field. I do not want to convert title to slug in Javascript - I have a controller action set up to do it and it will return the correct slug (the controller action converts it and it also check the resulting slug for uniqueness).
I just need to achieve the "onLostFocus" effect on Title textbox and populate the Slug textbox.
Any help appreciated.
EDIT:
With your help I've come up with this:
$('#Title').blur(
function(){
$.get('<%=Url.Action("TitleToSlug", "Services", new { title = HOW TO GET VALUE OF TITLE TEXTBOX HERE}) %>', function (data) {
$('#Slug').val(data);
});
}
)
How do I get the value for the Title textbox in the above code and provide it to the Url.Action() helper method so that it will generate the URL like this: ~/Services/TitleToSlug/my test title
thanks
Can you use the blur event handler?
$( '.yourSelector' ).blur(
function(){
// do stuff
}
)
精彩评论