[JavaScript] Send Data back to opener[RESOLVED]
Hey I am trying to send some data from a window i opened into a textbox that is on the main window.
the code in the new window
Code:
<script language="javascript">
function refresh_media(selected_media)
{
opener.document.forms['article'].article['test'].value += "[media=" + selected_media + "]";
} </script>
<input type="button" class="button" value="Insert Selected Media" onClick="refresh_media(this.form.media_list.options[this.form.media_list.selectedIndex].value);return false;" />
code in the parent window
Code:
<form method="post" name="article">
<input type="text" name="article[test]" />
</form>
The error i get when debugging is
Quote:
Error: opener.document.forms.article.article has no properties
If i change the name of the textbox from "article[test]" to just "test" then it works, but i want the form items like an array so that i can easly process the data via PHP.
Thanks
Re: [JavaScript] Send Data back to opener
If you have more than one intput element with the same name in your form then the elements will be put into a javascript array.
HTML Code:
<form name="test">
<input type="text" name="test[]" />
<input type="checkbox" name="test[]" />
</form>
<script type="text/javascript">
<!--
// number of elements in the array
alert(document.test['test[]'].length);
// an array items value
alert(document.test['test[]'][0].value);
//-->
</script>
Make sure you use index notation when accessing form elements with square brackets in their names as these are javascript meta characters.
** no **P.s: The name article[test] won't get passed to PHP as an array. You need to name it article[] with empty square brackes for PHP to create an array.
Re: [JavaScript] Send Data back to opener
VisualAd you can pass an array to PHP with an form item name of article[name].
When i get it from PHP its like $_GET['article']['test'] and it works fine
I havent tried out the code yet because im not at home. ill try it later
thanks
Re: [JavaScript] Send Data back to opener
Quote:
Originally Posted by john tindell
When i get it from PHP its like $_GET['article']['test'] and it works fine
Nice - I never actually realised that. The same still applies in the other post though, except for that line ;)