• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 157
  • Last Modified:

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
0
jabh01
Asked:
jabh01
  • 2
  • 2
  • 2
1 Solution
 
Sashi RachabattulaSCRUM Master, .NET Project LeadCommented:
send the code which u did
0
 
Sashi RachabattulaSCRUM Master, .NET Project LeadCommented:
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>
0
 
NoddegamraCommented:
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.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
jabh01Author Commented:

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.
0
 
NoddegamraCommented:
Hmmm... I haven't entered this area yet with JavaScript but if by "remote" you mean a page on another web site that's not in your web domain then I think there is security issues.

If you actually want to trigger an event then all you have to do is call the event as if it were a method of the element.

For example:

<HTML>
<BODY>
<P><INPUT id="onClickButton" type="button" value="OnClick event" onClick="alert('Button on click event')"></P>
<P><INPUT type="button" value="Fire onClick event" onClick="document.getElementById( 'onClickButton' ).onclick()"></P>
</BODY>
</HTML>

The "Fire onClick event" button actually calls the onclick function of the other button.  One thing to note here is that all event names must be in lowercase.
0
 
jabh01Author Commented:

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.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now