Link to home
Start Free TrialLog in
Avatar of jabh01
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
Avatar of Sashi Rachabattula
Sashi Rachabattula
Flag of India image

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.htm");
}

function selectChange()
{
mywin.document.getElementById("text1").value=select1.value
}
</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>
Avatar of Noddegamra
Noddegamra

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.selectedIndex ];
  . . .
  < 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].Combo );
  . . .
}

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.
Avatar of jabh01

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
Avatar of Noddegamra
Noddegamra

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 jabh01

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.