Lewis
Lewis

Reputation: 466

enable & disable input

I have a button that its disabled. But I need that when I click on my iFrame turns enabled and refresh the web page.

This is my button:

<input class="" id="deshacer" type="button"  value="Deshacer cambios"  disabled/>

I try with this, but doesn't works:

 $("#probando").on('click', function () {
   $("#deshacer").attr("disable", false);                             
    });

This is my iFrame:

<iframe  id="probando" src="<?php echo $url; ?>"  name="probando"></iframe>

Upvotes: 0

Views: 50

Answers (4)

attack
attack

Reputation: 1523

When testing this myself, I ran into some trouble getting the iframe element itself to accept the click event.

Instead, I had to use .contents(). (see: https://api.jquery.com/contents/)

Here's what worked for me:

$("#probando").contents().on('click', function () {
   $("#deshacer").prop("disabled", false);                             
});

Demo: https://jsfiddle.net/wk83pqf0/

Upvotes: 1

Remy Grandin
Remy Grandin

Reputation: 1686

If your ifram url is not on the exact same domain/subdomain, then your problem is most probably an origin policy one.

As a security measure, javascript can't access the content of an iframe if the iframe's url point to another site/domain. It's also true in the reverse : a JS code inside an iframe can't "climb up" the iframe

Upvotes: 0

sirgijan
sirgijan

Reputation: 9

Try this:

$("#probando").on('click', function () {
document.getElementById("deshacer").disabled = true;   
location.reload(true);                          
    });

Upvotes: -1

Ted
Ted

Reputation: 14927

Use this:

$("#probando").on('click', function () {
   $("#deshacer").prop("disabled", false);                             
});

(prop instead of attr, and disabled instead of disable)

Upvotes: 3

Related Questions