Link to home
Start Free TrialLog in
Avatar of jaws1021
jaws1021

asked on

child window and passing values..

I used javascript to open a new window(child)  when user clicks on button from parent window.

 On new window(child), I have textbox and button,  I need to get the value of the textbox and pass to parent window when user clicks on button, while closing the child window,  I need parent window to be refreshed too so I can display my value to textbox of the parent window , how can I do that?

1- parent window has button, clicked child window opened
2- child window has textbox and button, when button clicked, get the value of the textbox and pass to parent window and close child window.
3- refresh parent window and display the child windows value to text box in parent window.

I hope it is clear..
ASKER CERTIFIED SOLUTION
Avatar of basicinstinct
basicinstinct
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Michel Plungjan
Why refresh the parent?
Avatar of jaws1021
jaws1021

ASKER

because parents text box value empty, gets the value from childs textbox, that's why I am passing the value to parent. Once it is passed and close the child, I want to see the value in parent's textbox, that's why I need to refresh..
basicinsticts,  thank you for the example code, but I have a code(long one)  in server side for the click event of the button for child window, so how this will work with the function display result with your clientside code?
I think your and my idea of refresh is different.
Perhaps you mean update?
it is update but how can you see update if page doesn't refresh?
jaws

For the parent and child window to communicate the child window must have been opened with the "window.open" function.  That is most likely how it is done (the alternative would be <a href="popup.html" target="_blank">

As long as it uses "window.open" you can use the code in the example 'popup.html'.  You do not need to use the example parent code I posted.  

Both pages are intended to show you how to do it so you can build on it from there.
jaws, because we are dealing with client side code there is no need for a refresh - refreshing is only required when data is required from the server - javascript can do amazing magic without refreshing...
okay basicinstinct, I have done opening with window.open already you are right. But the portion I am having trouble is, passing the value from child's textbox to parent textbox when child's button clicked. On this button event I already did some inserting records , and I did that on server side, but you gave me example for clientside about passing values , so what I need to do?
this link is very complicated to me, I don't know C # also, but here where I eed help, I have used window.open already.. if I didn't have server side code for click event of button, your displayresult function would be great and solve my problem, since I already have click event for the button I can't use this function, or can I, just call the function from server side click event after saving my  child windows data to database?
above code works great but I cannot use use onclick on child window, I already have server sdie code for that, can I somehow do that function displayresult on server side?
If you send your child result to the server you can put the child in a frame and return
<script>
top.window.opener.document.frm.txt.value = '<%= whateverServerVar %>'
top.close()
</script>

Michel