I am trying to find a fallback solution for browsers who do not interpret the placeholder attribute for input elements. I have this simple jQuery Script but it throws an Error
SecurityError: "The operation is insecure.
this.value = val;"
Here's my script:
$('document').ready(function(){
$('input').each(function() {
if ($(this).val() === '' || $(this).val() === undefined) {
$(this).val($(this).attr('placeholder'));
}
});
});
Anyone any ideas what i can do? Or what i am doing wrong? Or what this error means? It happens in Firefox, haven't tested it in other Browsers yet.
I have just fixed a similar problem in my project. It turned out that I was trying to set a value of a <input type="file" ...>
input. It seems that you may be facing the same problem, because you are selecting all inputs of a document regardless of their type.
If you have firebug installed, try looking for the input that causes this error by inserting a log
command before trying to modify the input's value.
$('document').ready(function(){
$('input').each(function() {
if ($(this).val() === '' || $(this).val() === undefined) {
// Log goes here
window.console.log(
'There is an input without a value!',
this);
$(this).val($(this).attr('placeholder'));
}
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With