** This is not a duplication of any IE9 Placeholder issues. The reason being, the old JSP framework I use which is WebWork doesnt support placeholders in the HTML. **
What I want to do
I want to show a value in the field as placeholder
text. But if the user starts typing, the placeholder text should disappear.
Problem
If I type something and click outside, what I typed gets replaced with the placeholder text. I want to stop it from being replaced. If the input is empty, show the placeholder text, if the input has a value, don't replace the text.
Restriction
I also cant use placeholder
attribute for some technical reasons. (old framework and needs to support IE9).
Hope you guys can help.
var inputTextIDs = [
[".hotelLocaiton", "Location"],
["#agentTransfersSearchForm_filter_transfersName", "Location2"]
];
$.each(inputTextIDs, function(i, v) {
//$('input'+inputTextIDs[i][0]).val(inputTextIDs[i][1]);
$('input' + inputTextIDs[i][0]).on('change', function() {
var inputValue = $.trim($('input' + inputTextIDs[i][0]).val());
$('input' + inputTextIDs[i][0]).val(inputTextIDs[i][1]);
$('input' + inputTextIDs[i][0]).on('focus', function() {
$('input' + inputTextIDs[i][0]).val('');
}).on('blur', function() {
$('input' + inputTextIDs[i][0]).val(inputTextIDs[i][1]);
});
});
});