Current location: Hot Scripts Forums » General Web Coding » JavaScript » send data back to parent window


send data back to parent window

Reply
  #1 (permalink)  
Old 09-22-06, 05:01 AM
zoliky's Avatar
zoliky zoliky is offline
Aspiring Coder
 
Join Date: Jun 2006
Posts: 537
Thanks: 0
Thanked 0 Times in 0 Posts
send data back to parent window

I have the following form:

Code:
<form name="foo" enctype="multipart/form-data" action="sendmsgu2.php" method="post">
To:<br /><input type="text" name="name" size="30" maxlength="520" value="" /><br/> 
<font size="-1"><a href="#" onclick="window.open('address.php?do=addressbook', 'ad', 'width=400, height=250');">Address book</a></font><br/>
Subject:<br /><input type="text" name="subiect" size="30" maxlength="40" /><p></p>

<style type="text/css"> nobr {width:1%;} </style>
<div id="attdisplay">

  <!-- I need the content here -->
			
<span></span>
</div>

<input type="button" name="attachfiles" value="Attach files" onclick="window.open('files.php', 'attach', 'width=320, height=420');"><p></p>
<p><input type="submit" name="submit" value="Send message" />

</form>
If someone click on "Attach files" button, a new window appear (files.php).
In files.php the user has a button called "Start".

If user click on Start I need to send a data (for exameple a text string) back to parent window. I need to see the data between HTML tags:

Code:
<div id="attdisplay">

  <!-- I need the content here -->
			
<span></span>
</div>
What I need to do ?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 09-22-06, 06:38 AM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
place something like this in the button:
Code:
onclick="javascript:window.opener.document.myVar = 'newValue';"
greetz,
UnrealEd
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 09-24-06, 04:17 AM
zoliky's Avatar
zoliky zoliky is offline
Aspiring Coder
 
Join Date: Jun 2006
Posts: 537
Thanks: 0
Thanked 0 Times in 0 Posts
I explain my problem in more details. I spent many hours for a solution but no luck.

I have an HTML form to attach files. (like yahoo mail box, send an email to user and attach more files).

Code:
<form name="foo" enctype="multipart/form-data" action="sendmsgu2.php" method="post">
To:<br /><input type="text" name="name" size="30" maxlength="520" value="" /><br/> 
<font size="-1"><a href="#" onclick="window.open('address.php?do=addressbook', 'ad', 'width=400, height=250');">Address book</a></font><br/>
Subject:<br /><input type="text" name="subiect" size="30" maxlength="40" /><p></p>

<style type="text/css"> nobr {width:1%;} </style>
<div id="attdisplay">

<span></span>
</div>

<input type="hidden" name="attach1" value="">
<input type="hidden" name="attach2" value="">
<input type="hidden" name="attach3" value="">
<input type="hidden" name="attach4" value="">
<input type="hidden" name="attach5" value="">
<input type="hidden" name="attach6" value="">
<input type="hidden" name="attach7" value="">
<input type="hidden" name="attach8" value="">
<input type="hidden" name="attach9" value="">
<input type="hidden" name="attach10" value="">

<input type="button" name="attachfiles" value="Attach Files" onclick="window.open('files.php', 'attach', 'width=320, height=420');"><p></p>

Message:<br /><textarea name="mesaj" rows="4" cols="30"></textarea><br />
<input type="hidden" name="MAX_FILE_SIZE" value="2097152">

<p><input type="submit" name="submit" value="Trimite mesaj" />
</form>
An important line in my form :

Code:
<input type="button" name="attachfiles" value="Attach Files" onclick="window.open('files.php', 'attach', 'width=320, height=420');"><p></p>
When I click on "Attach Files" button I see a new JavaScript window. This Javascript window has input fields to select files. Something like :

Code:
<input type="file" name="file1" size=20>
<input type="file" name="file2" size=20>
<input type="file" name="file3" size=20>
The Javascript window has a button to submit selected options.
Now I need to send the "selected file names" to parent window, and put this names in parrent window hidden fields, here:

Code:
<input type="hidden" name="attach1" value="">
<input type="hidden" name="attach2" value="">
<input type="hidden" name="attach3" value="">
The following JavaScript function do a test for me (Send a string to hidden field):

Code:
  function BeginAttach()
  {  	
     self.opener.document.foo.attach1.value='Testing1'; 
     self.close();
  }
Now I go back to parent window. I open the HTML source in firefox, the problem is I don't see the value="" field populated.

Code:
<input type="hidden" name="attach1" value="">
<input type="hidden" name="attach2" value="">
<input type="hidden" name="attach3" value="">
I need to see this:

Code:
<input type="hidden" name="attach1" value="Testing1">
<input type="hidden" name="attach2" value="">
<input type="hidden" name="attach3" value="">
What I need to do? Please help, I appreciate any help!

Thank you very much !
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 09-24-06, 04:46 AM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
if you want to display a user input in an input field, you'll never see what is in there, only when you display it as text on the screen, or in inputfields such as password, text and textarea, dropdown.

for example: when i change the source of an image, it will never change the source in my sourcecode, it will change it "imaginary". if you submit the parent form, you'll see that the images will be uploaded.

Greetz,
UnrealEd
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 09-24-06, 05:43 AM
zoliky's Avatar
zoliky zoliky is offline
Aspiring Coder
 
Join Date: Jun 2006
Posts: 537
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
if you want to display a user input in an input field, you'll never see what is in there, only when you display it as text on the screen, or in inputfields such as password, text and textarea, dropdown.
Yes, I know.

My script store the value in hidden input field, but I want to see the value <input type="hidden" value="valuehere"> when I open firefox "View Sourcecode"

Yahoo do the same thing, every time the user add a new file the page is refreshed.

But I don't know how to refresh because I lost the hidden input value after refresh.

Last edited by zoliky; 09-24-06 at 05:45 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 09-24-06, 06:38 AM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
i guess they do a form submission, and then display the inputs again.
they'll have to use php to display them back on the screen i guess.

something like this:
Code:
window.opener.foo.attach1.value='Testing1';
window.opener.foo.submit();
window.close();
and then you check on the parent page whether you simply have to refresh the page, or parse the data.

Greetz,
UnrealEd
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 09-24-06, 06:47 AM
TwoD TwoD is offline
Community VIP
 
Join Date: Sep 2003
Location: 404
Posts: 1,813
Thanks: 0
Thanked 0 Times in 0 Posts
Again, you will never see the value of any field if you use "View Sourcecode", you will only see what the browser downloaded when requesting the page. Any changes you make to the page are stored but they do not have an effect on the source code itself.

But if you temporarily change the type of those fields to "text", you can see that they change on the page, but the sourcecode will always stay intact. That is ok since the browser does not use the sourcecode to keep track of the values of fields etc when a page is dynamically changed with scripts.

If you want to store a change on the page during a refresh, you either need to write a cookie and read it when the page loads, or send the data to the server so it can rewrite the sourcecode and make it have the changes before sending it back to the browser.
__________________
[W3Schools - learn all about the standards.] [QuirksMode - Browser Quirks] [MS's Online Reference Docs] [DOM in Gecko.]
Please pay attention to stickys, announcements and forum rules, thank you.
Please also remember Code Wrappers and [SOLVED] Marking, this helps everyone.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #8 (permalink)  
Old 09-25-06, 01:17 AM
zoliky's Avatar
zoliky zoliky is offline
Aspiring Coder
 
Join Date: Jun 2006
Posts: 537
Thanks: 0
Thanked 0 Times in 0 Posts
I put this JavaScript code

Code:
  function BeginAttach()
  {  	
     self.opener.document.foo.attach1.value='Testing1'; 
     self.opener.foo.submit();
     self.close();
  }
Firefox (Web Developer) plugin which has JavaScript debugging say the following:

self.opener.foo has no properties

What need to do now?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #9 (permalink)  
Old 09-25-06, 03:49 AM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
try:
Code:
function BeginAttach()
  {  	
     self.opener.document.foo.attach1.value='Testing1';   
     self.opener.document.foo.submit();
     self.close();
  }
this will submit the form, now you have to make a php, perl or asp script that will display the data that is allready filled in as a value in the inputs

Greetz,
UnrealEd
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #10 (permalink)  
Old 09-25-06, 04:54 AM
zoliky's Avatar
zoliky zoliky is offline
Aspiring Coder
 
Join Date: Jun 2006
Posts: 537
Thanks: 0
Thanked 0 Times in 0 Posts
Unrealed thanks for help ! I solve the problem
Now, the child window send the data to parent window, using this function:

Code:
function BeginAttach()
{  	
   self.opener.document.foo.attach1.value= 'Testing1'; 
   self.opener.document.foo.submit();
   self.close();
}
In parent window source code I have this line:

Code:
<input type="hidden" name="attach1" value="Testing1">
OK.. now I want to open the child window again, and I want to send the value "Testing1" from parent to child window.

The child window has another hidden field:

Code:
<input type="hidden" name="attach1" value="">
I need to send "Testing1" from parent hidden field to chil hidden field.

Exist a way to do this without cookies or sessions?

Thank you very much !

Last edited by zoliky; 09-25-06 at 05:40 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
send data to email jilshi Everything Java 0 04-02-04 09:50 PM


All times are GMT -5. The time now is 01:59 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.