could someone help me to figure out if it is possible to take part of the value entered into an input field and change the value. What I am trying to do is make sure that addresses are entered correctly. So if someone puts in:
111 Circleview Road it would be changed to 111 Circleview Rd.
This is what I am trying with but having no luck, so I don’t know if I am doing this wrong or if this is not possible to do with jQuery
$("#address").blur(
function(){
switch ($(this).val()){
case 'Road':
case 'road':
$(this).replaceWith("Rd.");
break;
case 'Street':
case 'street':
$(this).replaceWith("St.")
default:
$(this).val();
break;
}
}
);
Just use regular expression to find the words – it’s just string manipulation in JavaScript.
Example: http://jsfiddle.net/jonathon/4Yuym/
You don’t need to use
$(this).val()on an input element sincevalueis part of the element’s native properties – so you can usethis.valueto get/set.