?
Solved

Trigger an event on another page

Posted on 2003-02-20
6
Medium Priority
?
156 Views
Last Modified: 2012-05-04
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
Comment
Question by:jabh01
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 4

Expert Comment

by:Sashi Rachabattula
ID: 7992059
send the code which u did
0
 
LVL 4

Expert Comment

by:Sashi Rachabattula
ID: 7992088
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
 
LVL 1

Expert Comment

by:Noddegamra
ID: 7992162
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
Industry Leaders: 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!

 

Author Comment

by:jabh01
ID: 7992930

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
 
LVL 1

Accepted Solution

by:
Noddegamra earned 300 total points
ID: 7997711
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
 

Author Comment

by:jabh01
ID: 8000077

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

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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question