Trigger a function from pop up window and arguments question...

S

Sally B.

Hi,

I have a main page that opens a pop up window when the user clicks a
link. The pop up window is a menu and when the user clicks the item, it
populates a form input element on the 'parent' window.

My question is: this new populated form element is the value that I use
to change a style.

onchange does not watch this form element because of getelementbyid, so
it doesn't trigger the function needed to change the style. onchange
works fine if I just manually input a value into the text box.

Any other way to fire the function off when the user picks their
selection from the pop-up window? I was thinking I could use
window.opener.function()? But how do I pass the form from the parent
window? From the pop up window, I don't use this.form, what do I
use?something like window.opener.form[0] ?

thks
 
M

marss

Sally B. напиÑав:
onchange does not watch this form element because of getelementbyid, so
it doesn't trigger the function needed to change the style. onchange
works fine if I just manually input a value into the text box.

Input value into the text box by code and then explicitly call function
which you use as onchange event handler.
window? From the pop up window, I don't use this.form, what do I
use?something like window.opener.form[0] ?

opener is ahother window and it has no "form" property, use
opener.document.form[0].

But better you can define a function in the main window and call it
from a popup window.
e.g.

main window

<html>
<body>
<script type=text/javascript>
function foo(val){
document.getElementById("tb1").value = val;
tb1Changed(val);
}
function tb1Changed(val){
alert("textbox value: " + val);
}
</script>
<input type=button
onclick="window.open('2.htm','popup','height=300,width=300');"
value="Open popup window">
<input type="text" id="tb1" onchange="tb1Changed(this.value)">
</body>
</html>


popup window

<html>
<body>
<input type=button onclick="opener.foo('test');" value="Change main
window">
</body>
</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,233
Members
46,820
Latest member
GilbertoA5

Latest Threads

Top