A.M
A.M

Reputation: 63

make all text fields in parent document of iframe, read only using jquery or javascript

    parent.document.getElementById('')

I am using above code to manipulate elements individually in parent document. but i want to select all text field of parent document in one call and make them readonly. Because there are more than 70 fields and setting their properties one by one will be a long code.

 window.parent.$("form input:text").setAttribute("readOnly","true");    

and

 $(":text").parent().setAttribute("readOnly","true");

I have tried both of these above codes but nothing worked.

Upvotes: 0

Views: 2261

Answers (6)

arclite
arclite

Reputation: 528

try this:

$("iframe").contents().find("form input:text").attr('readonly',true);

or

$("iframe").contents().find("form input[type=text]").attr('readonly',true);

Upvotes: 0

abcdef
abcdef

Reputation: 1

This worked for me:

window.parent.$("form input:text").attr('readonly','readonly');

Upvotes: 0

Patrick Zeng
Patrick Zeng

Reputation: 34

This should work for you,

$(':text').each(function () {
            $(this).attr('disabled', 'disabled');
        });

Upvotes: 0

D4V1D
D4V1D

Reputation: 5849

Try .attr('readonly','readonly');

JsFiddle

Upvotes: 0

arclite
arclite

Reputation: 528

i think this will work for you

window.parent.$("form input[type=text]").setAttribute("readOnly","true"); 

Upvotes: 0

palaѕн
palaѕн

Reputation: 73916

You can do this using .prop():

$("form input:text").prop( "readonly", true );

Fiddle Demo

Upvotes: 1

Related Questions