Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery: Javascript throws Error "The operation is insecure" when setting value

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.

like image 429
Andresch Serj Avatar asked Aug 02 '12 15:08

Andresch Serj


1 Answers

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'));
           }
       });
});
like image 142
Igor Zinov'yev Avatar answered Nov 01 '22 04:11

Igor Zinov'yev