I have a simple page with iframe. In this frame there are a three input fields, which user fill in. How to get this data in every input field with js?
Here is js:
<script type="text/javascript"> var ticket = window.frames[0].document.getElementById('ticket').ticket; alert(ticket); </script>
And i have inside frame:
<input type='text' name='ticket' id='ticket'...
Nothing happens when I fill all 3 inputfield and press ok. How to save this data, wh开发者_如何学运维ich filled in this input fields to .txt file, than I can grab this txt by php and fill into database.
I'm not convinced that iframes are accessible via the window.frames
property. You could try something like this:
var frame = document.getElementsByTagName("iframe")[0]
, form = frame.contentDocument.forms[0];
alert("OK: ticket=" + form.ticket.value);
Storing the form values in the database is another issue entirely. It might be easiest to avoid JavaScript entirely and simply make the form within the iframe perform a POST to your own PHP handler which can save the contents as needed.
I spent a lot of time trying to figure out how to exchange data from between text boxes in two Iframes. (I am the author of both iframes). After a lot of wasted time and looking for solutions on the internet the solution was, of course, incredible easy. Everyone on the internet is doing MUCH more complicated things. For those of you who want to do something simple!
I have a main page with two Iframes (ID = ifr1
and ifr2
). Each frame had a text box (ID = tb1
(in ifr1
)). In javascript you can get the contents of tb1
in iframe ifr2
by simply using
parent.ifr1.tb1.value
or parent.ifr1.document.getElementByID(‘tb1’).value.
To change the value, obviously"
parent.ifr1.tb1.value=”whatever”
or parent.ifr1.document.getElementByID(‘tb1’).value=”whatever”
You can also access a variable from ifr1
from ifr2
by using
parent.ifr1.var_in_ifr1
where var_in_ifr1
is defined in the script of ifr1
var var_in_ifr1=”whatever”
精彩评论