/    Sign up×
Community /Pin to ProfileBookmark

how to pass a value from parent JS to child window

Hi All,
I need to pass a value from parent JSP to child window / pop up window.

in pop up window, i have a textbox which has id as rs and name as remSeconds

from parent i need to pass the value calculated from a timer which is remainingTime..

childWindow.document.remseconds.value=remainingTIme
or
childWindow.document.getElementById(‘rs’).value=remainingTime.

please help me how to pass this value from parent to child as timer which needs to be update the timing count down in parent

to post a comment
JavaScript

14 Comments(s)

Copy linkTweet thisAlerts:
@mityaJan 10.2010 — [CODE]windowname.document.getElementById('idOfField').value = 'text to insert';[/CODE]
Copy linkTweet thisAlerts:
@blackpantherauthorJan 11.2010 — i have tried that also.. the problem is it says is null or undefined.. can anyone tell me what it really means and whats the difference in my case.

i have made the child window var a global variable and accessed it..

eg:

var childWindow;

function opwnWIndow(){

window.open().. code goes here}

function Timer(){

childWindow.document.getElementById('id').value=some variable;

}
Copy linkTweet thisAlerts:
@criterion9Jan 11.2010 — <i>
</i>var childWindow;
function opwnWIndow(){
childWindow = window.open()... code goes here}
Copy linkTweet thisAlerts:
@blackpantherauthorJan 11.2010 — done exactly the same. not working
Copy linkTweet thisAlerts:
@blackpantherauthorJan 11.2010 — this works fine in IE but not in Firefox.. can anybody tell me why. its urgent

childWindow.document.getElementById('remSeconds').value = remainingTime;

it didnt work in FF, childWindow.document.getElementById('remSeconds') is null is the error in get in error console
Copy linkTweet thisAlerts:
@FangJan 11.2010 — Is the ID unique? Does it reference a control element?
Copy linkTweet thisAlerts:
@blackpantherauthorJan 11.2010 — this is in the child window....

<input type='text' name='remSeconds' id='remSeconds' size='2'>
Copy linkTweet thisAlerts:
@FangJan 11.2010 — What are the arguments in window.open() ?
Copy linkTweet thisAlerts:
@blackpantherauthorJan 11.2010 — var childWindow =null;

var timeoutpath = "timeout.html";

function openWindow() {

var options = 'width=350,height=150,left=350,top=250,resizable=no,scrollbars=no,menubar=no,status=no,toolbar=no,location=no,titlebar=no,personalbar=no,dialog=no';
childWindow = window.open(timeoutpath, "timeWindow", options);
}
Copy linkTweet thisAlerts:
@FangJan 11.2010 — When and where is the statement executed?

[I]childWindow.document.getElementById('remSeconds').value = remainingTime;[/I]
Copy linkTweet thisAlerts:
@blackpantherauthorJan 11.2010 — this open window is called from a parent script and it opens in sequence like

first i called the open window function

second i call the timer function in which it calculates the remainingTime and updates in the child window. my doubt is whether there is no sync like before the window gets open and all things are written, the remaining TIme is getting called.. lots of confusion
Copy linkTweet thisAlerts:
@criterion9Jan 11.2010 — Is it possible that the DOM hasn't been loaded in the child window before you are trying to access it?
Copy linkTweet thisAlerts:
@blackpantherauthorJan 12.2010 — hi guys,

the reference created for the childwindow is the problem in my case. so i didnt try to create a reference and put all the code related to the child window in the child window as a script.

so now there is no need of the reference for the child window.. so only i call open window from parent js.

atlast the issue is solved....

'

NOTE:getElementById is a mysterious problem in FireFox..

Thanks to all who came up with giving solution to me.. Hope to meet u all with a new problem?
Copy linkTweet thisAlerts:
@AntraSep 17.2020 — Can you share code snippet how you figured to open child window
×

Success!

Help @blackpanther spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...