jabh01
asked on
Trigger an event on another page
Is it possible to trigger an event on anothe page?
For instance if "pagea" opens "pageb" and "pagesb" modifies the content of a select box on "pagea" is there any way for an "onchange" event attached to the select box to fire.
I have tried changing the "selectedindex" from pageb and the select box does change to contain the right option but the attached "onchange" event is ignored
For instance if "pagea" opens "pageb" and "pagesb" modifies the content of a select box on "pagea" is there any way for an "onchange" event attached to the select box to fire.
I have tried changing the "selectedindex" from pageb and the select box does change to contain the right option but the attached "onchange" event is ignored
send the code which u did
suppose this is page.htm when u click the button it will pop up page2.htm
when u select from combo box it will be shown in textbox of page2.htm
-------page.htm----------- ---------
<script>
var mywin;
function popup()
{
mywin=window.open("page2.h tm");
}
function selectChange()
{
mywin.document.getElementB yId("text1 ").value=s elect1.val ue
}
</script>
<select onchange=selectChange()>
<option value=abc>abc</option>
....
</select>
<input type=button name=b1 value=popup onclick=popup()>
----------------page2.htm- ---------- --------
<input type=text id=text1>
when u select from combo box it will be shown in textbox of page2.htm
-------page.htm-----------
<script>
var mywin;
function popup()
{
mywin=window.open("page2.h
}
function selectChange()
{
mywin.document.getElementB
}
</script>
<select onchange=selectChange()>
<option value=abc>abc</option>
....
</select>
<input type=button name=b1 value=popup onclick=popup()>
----------------page2.htm-
<input type=text id=text1>
Onchange events are only fired when the user makes a change (i.e. non-programatically). To get around this problem I tend to write a function which takes a field as it's argument. For example:
<SCRIPT language="JavaScript">
function e_onComboChange( oField ) {
var sValue = oField.options[ oField.options.selectedInd ex ];
. . .
< other code >
}
</SCRIPT>
Then on page 1 have the following event on the SELECT element:
<SELECT name="Combo" onChange="e_onComboChange( this)">
Then in the script in page 2 which changes the value of the drop down box call the event handler function. Let's say that a variable called "page1" is a reference to the first page's window (i.e. the frame). To call the event handler it would look something like:
function changeCombo() {
< code to set value of drop down >
. . .
page1.e_onComboChange( page1.document.forms[0].Co mbo );
. . .
}
Using this approach means that as long as you can get a handle on the field you can call the event handler whereever you wish.
<SCRIPT language="JavaScript">
function e_onComboChange( oField ) {
var sValue = oField.options[ oField.options.selectedInd
. . .
< other code >
}
</SCRIPT>
Then on page 1 have the following event on the SELECT element:
<SELECT name="Combo" onChange="e_onComboChange(
Then in the script in page 2 which changes the value of the drop down box call the event handler function. Let's say that a variable called "page1" is a reference to the first page's window (i.e. the frame). To call the event handler it would look something like:
function changeCombo() {
< code to set value of drop down >
. . .
page1.e_onComboChange( page1.document.forms[0].Co
. . .
}
Using this approach means that as long as you can get a handle on the field you can call the event handler whereever you wish.
ASKER
This is a good idea and I will try and extend it further as the onChange action actually effects about 30 elements of Page1.
It still does not tell me if there is a way to trigger an event (apart from focus events) on a "remote" page. Like can I generate an onclick etc.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you so much!
I had tried this and failed but your comment about it having to be in lower-case saved the day!!!!
J.