Posted 11 February 2013 - 13:29
Posted 11 February 2013 - 13:36
<head>
<script type="text/javascript">
function ClearPlaceHolder (input) {
if (input.value == input.defaultValue) {
input.value = "";
}
}
function SetPlaceHolder (input) {
if (input.value == "") {
input.value = input.defaultValue;
}
}
</script>
</head>
<body>
<input type="text" value="Please fill this field" onfocus="ClearPlaceHolder (this)" onblur="SetPlaceHolder (this)" />
</body>
Posted 11 February 2013 - 13:53
Axel, on 11 February 2013 - 13:42, said:
Posted 11 February 2013 - 13:58
.the-form input:focus + label.placeholder {
display: none;
}
This will hide the adjacent placeholder whenever the input gains focus. I forked your fiddle and also set the position on the input to relative so the different z-index actually takes effect, as suggested by Jamie.Posted 11 February 2013 - 14:32
Axel, on 11 February 2013 - 13:42, said:
Posted 11 February 2013 - 15:00
Axel, on 11 February 2013 - 13:29, said:
Posted 11 February 2013 - 17:07
Posted 11 February 2013 - 18:46
<script>
// placeholder polyfill
$(document).ready(function(){
function add() {
if($(this).val() == ''){
$(this).val($(this).attr('placeholder')).addClass('placeholder');
}
}
function remove() {
if($(this).val() == $(this).attr('placeholder')){
$(this).val('').removeClass('placeholder');
}
}
// Create a dummy element for feature detection
if (!('placeholder' in $('<input>')[0])) {
// Select the elements that have a placeholder attribute
$('input[placeholder], textarea[placeholder]').blur(add).focus(remove).each(add);
// Remove the placeholder text before the form is submitted
$('form').submit(function(){
$(this).find('input[placeholder], textarea[placeholder]').each(remove);
});
}
});
</script>