tags:

views:

624

answers:

2

I have the following html:

<html>
    <head></head>
    <body>
        <form>
            <input id="msg" type="text" value="oldValue" />
        </form>
        <script src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js"&gt;&lt;/script&gt;
        <script>
            $().ready(function() {
                var m = $("#msg");
                alert(m.val()); // returns oldValue
                m.val("newValue"); // this doesn't make the browser show newValue instead of oldValue
                alert(m.val()); // returns newValue
                // and in the end, the browser still shows oldValue for the input
            });
        </script>
    </body>
</html>

This code runs perfect, but when placed in a facebox (which just creates an iframe and shows it like a floating window), the code fails to update the input's content.

The parent also has jQuery, but that shouldn't influence anything I guess.

Any ideas why it's failing?

+1  A: 

Unable to replicate on Firefox 3, IE 7 or Chrome 2. The code works fine (using newValue everywhere appropriate) regardless of whether it's in an iframe.

Have you tested your reduced sample implementation, as opposed to your original? Because I suspect we have a problem where you think they're equivalent and they aren't.

Of course, the good news is that if your posted sample implementation works, then all you have to do is add in elements from your actual implementation until something breaks.

chaos
actually, in my implementation it's loaded from the same domain, the pasted version is just to be able to share it as my implementation is a lot bigger :)
Prody
A: 
doc = xframe.contentWindow.document || xframe.document || xframe.contentDocument || xframe.contentWindow && xframe.contentWindow.document || null;

if(!doc)
{
  alert("Error");
  return false;
}

var m = $(doc).find("#msg");
andres descalzo
if you would have carefully read my description, you would have found out that my script succesfully finds the #msg element, can read it's value, but can't set it.
Prody
ok, what I'm going on is an alternative to access the data. then this in your ability adapt. One thing is do not be useful, and something else that is a mistake.
andres descalzo
If the item is in an iframe, you can only access using the iframe object . we must see if you got the same id in the iframe in the current document, ¿ok?
andres descalzo