Results 1 to 4 of 4

Thread: [JavaScript] Send Data back to opener[RESOLVED]

  1. #1

    Thread Starter
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099

    Resolved [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
    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
    Last edited by john tindell; Feb 7th, 2005 at 03:24 AM.

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    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.
    Last edited by visualAd; Feb 6th, 2005 at 01:14 PM. Reason: False Statement - See post below.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3

    Thread Starter
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099

    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

  4. #4
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    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
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width