views:

42

answers:

1

Greetings, js masters. 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.

Thanks

+1  A: 

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.

maerics