473,412 Members | 5,714 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

How can I call page function from automation code?

Hey all,

I am automating a web page from Visual Foxpro. I can control all the
textboxes, radio buttons, and command buttons using syntax such as:

oIE.Document.Forms("searchform").Item(<name>).Valu e = <myvalue>

But I cannot control a dropdown with an onchange event. I can set the
dropdown's value and selectedIndex, but then calling the onChange() or
Click() does not do anything. It only seems to fire the onchange if I
use it interactively.

I know what the onChange calls on the form, and I can call the
function directly, but I don't know how. How does one call a straight
JavaScript function that is in the script portion of the web page and
have it fire as if it was called from the page itself?

Just point me to any docs and I should be able to figure it out. I am
just missing this one step, but it is crucial for this manipulation...

You can email me at: junk (at) removethis.sutekh137.net, and I will
try to monitor the newsgroup.

Thanks in advance!
JoeK
Jul 23 '05 #1
3 3999
jo*@sutekh137.net (JoeK) wrote in message news:<47*************************@posting.google.c om>...
Hey all,

I am automating a web page from Visual Foxpro.
I do not know Visual Foxpro. Hope that my answer will still be on
track.

oIE.Document.Forms("searchform").Item(<name>).Valu e = <myvalue>

But I cannot control a dropdown with an onchange event. I can set the
dropdown's value and selectedIndex,
I assume you are setting these things from javascript.
but then calling the onChange() or
Click() does not do anything.
I asume you mean the event handlers are not called when you chanage
the values. This is true. They are not called. You need to call
the functions directly after you change the data in javascript.
It only seems to fire the onchange if I
use it interactively.
True. The event handlers response only to screen input.

I know what the onChange calls on the form, and I can call the
function directly, but I don't know how.
It is a standard call. The user of the this keyword makes the
function call looks special, but it is a standard function call. You
have to supply whatever the this would have supplied because you will
not be in the this scope chain. ( I do not think, but you can try.)
How does one call a straight
JavaScript function that is in the script portion of the web page and
have it fire as if it was called from the page itself?
Here is my file where I have one style of call with the this and
another without. It is probably best to first run this file. It will
explain more about what is going on.

Robert

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<Title>My color test</Title>
<script type="text/javascript">

function processColors(form)
{
var box;
box = document.createElement("p");
document.body.appendChild(box);
box.innerHTML = "<p>Display all <b>three</b> inputs.</p>";

for (var i=1; i<=3; i++)
{

// Here I call the onchange function.
displayOneColor(form,"color"+i);
}

return true;
} //end function

function displayOneColor (form,theColor)
{
var colorList = ["green","blue","red","black"];
var boxColor;
var box;

boxColor=form.elements[theColor].value;
box = document.createElement("p");
document.body.appendChild(box);
box.innerHTML =
"<p><span style='color:" + colorList[boxColor] + "';>" +
"You picked color "+ colorList[boxColor] +
" for input " + theColor + "." +
"</span></p>";
}
function validateOnSubmit(form)
{
alert("in validateOnSubmit.");
}

</script>
</HEAD>
<BODY >
<p>This files show how you can call an onchange event
handler directly in the onchange event or indirectly from
another function. The
function displayOneColor is called from each of the onchange
event handler in the select tags. To see the direct call, look in the
for loop
of processColors.</p>
<p>Changing on of the colors in the three select box
will display a message at the bottom of the screen.
Clicking on the GO button will show all three color
selections. Clicking on Submit Query will erase all
the color messages since the file is being reloaded. </p>

<form name="form1"

Pick color 1:
<SELECT name="color1" name=color1 style="WIDTH: 180px"
onchange="displayOneColor(this.form,this.name);">
<OPTION value = "0" >Green
<OPTION value = "1" >Blue
<option value = "2" >Red
<option value = "3" >Black
</OPTION></SELECT>
<br><br>
Pick color 2:
<SELECT name="color2" style="WIDTH: 180px"
onchange="displayOneColor(this.form,this.name);">
<OPTION value = "0" >Green
<OPTION value = "1" >Blue
<option value = "2" >Red
<option value = "3" >Black
</OPTION></SELECT>
<br><br>
Pick color 3:
<SELECT name="color3" style="width: 180px"
onchange="displayOneColor(this.form,this.name);">
<OPTION value = "0" >Green
<OPTION value = "1" >Blue
<option value = "2" >Red
<option value = "3" >Black
</OPTION></SELECT>
<br>
<input TYPE=BUTTON NAME="cmdCalc" VALUE="GO"
onClick="processColors(this.form)">
<br><br>
<input type="submit">

</BODY>
</HTML>
Jul 23 '05 #2
JoeK wrote:
I am automating a web page from Visual Foxpro.
The odds are that there are not many (if any) regulars on this group who
have ever done that.
I can control all the textboxes, radio buttons,
and command buttons using syntax such as: oIE.Document.Forms("searchform").Item(<name>).Valu e = <myvalue>
That code strongly resembles VBScript (is it?). A javascript (or,
probably more correctly, JScript) version might go:-

oIE.document.forms["searchform"].elements[<name>].value = '<myvalue>';

And automating IE with WSH might acquire a reference to a new IE
application as:-

var oIE = new ActiveXObject("internetexplorer.application");

- but you haven't gone into how you are getting your - oIE - reference.
But I cannot control a dropdown with an onchange event. I can set the
dropdown's value and selectedIndex, but then calling the onChange() or
Click() does not do anything. It only seems to fire the onchange if I
use it interactively.
Browser form controls do not tend to fire change events when their
values are set through scripts. But scripts that set the values of
controls may call the corresponding onchange handlers themselves as
method of the form control. In JScript that would be:-

var frmEls = oIE.document.forms["searchform"].elements;
frmEls[<name>].onclick();
- or -
frmEls[<name>].click(); //for the - click - method.

(javascript/JScript/ECMAScript is case sensitive.)
I know what the onChange calls on the form, and I can call the
function directly, but I don't know how. How does one call a straight
JavaScript function that is in the script portion of the web page and
have it fire as if it was called from the page itself?

<snip>

In JScript, as above, but in whichever language you are using I don't
know. Though it will almost certainly follow a similar form/structure.

Richard.
Jul 23 '05 #3
> > How does one call a straight
JavaScript function that is in the script portion of the web page and
have it fire as if it was called from the page itself?


There is a more elegant way of calling the event handler. Since the
handler are functions, you can call the function directly. This is an
example:
// Call the event handler for the select
form.elements["color" + i].onchange();
"Note, however, that invoking an event handler is not a way to
simulate what happens when the event actually occurs. If we invoke
the onclick method of a Link object, for example, it does not make the
browser follow the link and load a new document." from Javascrip: The
Definitive Guide page 357.

Here is the revised function...

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<Title>My color test</Title>
<script type="text/javascript">

function processColors(form)
{
var box;
box = document.createElement("p");
document.body.appendChild(box);
box.innerHTML = "<p>Display all <b>three</b> inputs.</p>";

for (var i=1; i<=3; i++)
{

// Here I call the onchange function.
// The commented line directly invokes the underlaying
// function.
// displayOneColor(form,"color"+i);

// Call the event handler for the select
form.elements["color" + i].onchange();
}

return true;
} //end function

function displayOneColor (form,theColor)
{
var colorList = ["green","blue","red","black"];
var boxColor;
var box;

boxColor=form.elements[theColor].value;
box = document.createElement("p");
document.body.appendChild(box);
box.innerHTML =
"<p><span style='color:" + colorList[boxColor] + "';>" +
"You picked color "+ colorList[boxColor] +
" for input " + theColor + "." +
"</span></p>";
}
function validateOnSubmit(form)
{
alert("in validateOnSubmit.");
}

</script>
</HEAD>
<BODY >
<p>This files show how you can call an onchange event
handler directly in the onchange event or indirectly from
another function. The
function displayOneColor is called from each of the onchange
event handler in the select tags. To see the direct call, look in the
for loop
of processColors.</p>
<p>Changing on of the colors in the three select box
will display a message at the bottom of the screen.
Clicking on the GO button will show all three color
selections. Clicking on Submit Query will erase all
the color messages since the file is being reloaded. </p>

<form name="form1"

Pick color 1:
<SELECT name="color1" name=color1 style="WIDTH: 180px"
onchange="displayOneColor(this.form,this.name);">
<OPTION value = "0" >Green
<OPTION value = "1" >Blue
<option value = "2" >Red
<option value = "3" >Black
</OPTION></SELECT>
<br><br>
Pick color 2:
<SELECT name="color2" style="WIDTH: 180px"
onchange="displayOneColor(this.form,this.name);">
<OPTION value = "0" >Green
<OPTION value = "1" >Blue
<option value = "2" >Red
<option value = "3" >Black
</OPTION></SELECT>
<br><br>
Pick color 3:
<SELECT name="color3" style="width: 180px"
onchange="displayOneColor(this.form,this.name);">
<OPTION value = "0" >Green
<OPTION value = "1" >Blue
<option value = "2" >Red
<option value = "3" >Black
</OPTION></SELECT>
<br>
<input TYPE=BUTTON NAME="cmdCalc" VALUE="GO"
onClick="processColors(this.form)">
<br><br>
<input type="submit">

</BODY>
</HTML>
I know the prior poster mentioned this. I thought I was invoking the
event function, but I was invoking my event function not the DOM event
function and I didn't know I could do it this way until today.

Robert

Robert
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Chris Michael | last post by:
Hello everybody, Newbie here. I've been working on this for the last two days and I can't figure out where this problem is. I think it's something so obvious, but I can't see it! OK, firstly...
6
by: mork | last post by:
I am so frustrated - any help is appreciated. When trying to use common functions like Left and/or Mid I get the following error: Run-time Error '5': Invalid Procedure Call or Argument In my...
4
by: Chuck | last post by:
A report has many different groups of multiple pages each. Each group starts on a new page. The report is printed on both sides of the paper. I would like to be able to have each group start on...
1
by: Kannan | last post by:
Hello, I know this has been answered before but I cannot seem to get this working for the life of me... Any help/pointers would be greatly appreciated. I am trying to call a set of C# functions...
10
by: Clint | last post by:
Hey all - I'm having a really confusing problem concerning a web service. Right now, I have an application that needs to call a web service that does nothing but return "true" (this will...
7
by: Gabe Covert | last post by:
I'm attempting to implement a 3rd party COM library in a C# application, and have run up against the following problem in my development. I am trying to use a particular method call of an object,...
4
by: gs | last post by:
I have searched Google, MSDN,... for a week. I am still unable to make available functions in my csharp dll as native windows functions for some legacy non dotnet application I just want to...
0
by: ultranet | last post by:
Our code is using HRESULT AutoWrap(int autoType, VARIANT *pvResult, IDispatch *pDisp, LPOLESTR ptName, int cArgs...) { provided in one of the Technical papers. The following call fails on site...
11
by: yangsuli | last post by:
i want to creat a link when somebody click the link the php script calls a function,then display itself :) i have tried <a href=<? funtion(); echo=$_server ?>text</a> but it will call the...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.