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, which 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
发布评论
评论(2)
我不相信 iframe 可以通过 window.frames 属性访问。您可以尝试这样的操作:
将表单值存储在数据库中完全是另一个问题。最简单的方法可能是完全避免 JavaScript,只需让 iframe 中的表单对您自己的 PHP 处理程序执行 POST,该处理程序可以根据需要保存内容。
I'm not convinced that iframes are accessible via the
window.frames
property. You could try something like this: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.
我花了很多时间试图弄清楚如何在两个 Iframe 中的文本框之间交换数据。 (我是两个 iframe 的作者)。经过大量浪费时间并在互联网上寻找解决方案之后,解决方案当然非常简单。互联网上的每个人都在做远更复杂的事情。对于那些想做简单事情的人!
我有一个带有两个 Iframe 的主页(ID =
ifr1
和ifr2
)。每个框架都有一个文本框(ID =tb1
(在ifr1
中))。 即可获取 iframeifr2
中tb1
的内容在 javascript 中,您只需使用
parent.ifr1.tb1.value
或parent.ifr1 .document.getElementByID('tb1').value.
要更改值,显然是“
parent.ifr1.tb1.value=”whatever”
或parent.ifr1.document .getElementByID('tb1').value=”whatever”
您还可以使用
parent.ifr1 从
ifr2
访问ifr1
中的变量。 var_in_ifr1 其中
var_in_ifr1
是在ifr1
的脚本中定义的var var_in_ifr1=”whatever”
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
andifr2
). Each frame had a text box (ID =tb1
(inifr1
)). In javascript you can get the contents oftb1
in iframeifr2
by simply usingparent.ifr1.tb1.value
orparent.ifr1.document.getElementByID(‘tb1’).value.
To change the value, obviously"
parent.ifr1.tb1.value=”whatever”
orparent.ifr1.document.getElementByID(‘tb1’).value=”whatever”
You can also access a variable from
ifr1
fromifr2
by usingparent.ifr1.var_in_ifr1
wherevar_in_ifr1
is defined in the script ofifr1
var var_in_ifr1=”whatever”