473,703 Members | 2,328 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Fo rms("searchform ").Item(<name>) .Value = <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.sute kh137.net, and I will
try to monitor the newsgroup.

Thanks in advance!
JoeK
Jul 23 '05 #1
3 4050
jo*@sutekh137.n et (JoeK) wrote in message news:<47******* *************** ***@posting.goo gle.com>...
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.Fo rms("searchform ").Item(<name>) .Value = <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(f orm)
{
var box;
box = document.create Element("p");
document.body.a ppendChild(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","blac k"];
var boxColor;
var box;

boxColor=form.e lements[theColor].value;
box = document.create Element("p");
document.body.a ppendChild(box) ;
box.innerHTML =
"<p><span style='color:" + colorList[boxColor] + "';>" +
"You picked color "+ colorList[boxColor] +
" for input " + theColor + "." +
"</span></p>";
}
function validateOnSubmi t(form)
{
alert("in validateOnSubmi t.");
}

</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="displ ayOneColor(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="displ ayOneColor(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="displ ayOneColor(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="proces sColors(this.fo rm)">
<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.Fo rms("searchform ").Item(<name>) .Value = <myvalue>
That code strongly resembles VBScript (is it?). A javascript (or,
probably more correctly, JScript) version might go:-

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

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

var oIE = new ActiveXObject(" internetexplore r.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.fo rms["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(f orm)
{
var box;
box = document.create Element("p");
document.body.a ppendChild(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","blac k"];
var boxColor;
var box;

boxColor=form.e lements[theColor].value;
box = document.create Element("p");
document.body.a ppendChild(box) ;
box.innerHTML =
"<p><span style='color:" + colorList[boxColor] + "';>" +
"You picked color "+ colorList[boxColor] +
" for input " + theColor + "." +
"</span></p>";
}
function validateOnSubmi t(form)
{
alert("in validateOnSubmi t.");
}

</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="displ ayOneColor(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="displ ayOneColor(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="displ ayOneColor(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="proces sColors(this.fo rm)">
<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
1954
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 in a very simple page (please see www.intomobiles.com/test3.htm - it just displays the code that i use in an asp page) I call a function "processForm". The actual form is described in an asp page and is SSI linked to the page (for the full...
6
20660
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 searches it appears I am not the first, but the solution seems to be missing references. When I check my references, none are labelled as missing. I've removed all references and re-added them and the error
4
4539
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 a right hand page, that is, to be printed on an odd numbered page. something like iif(page mod0 is true then force to next page). All suggestions will be gratefully received. Chuck ....
1
12604
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 from Javascript.... For this I created a c# class lib. and put all the functions there. The class library itself references other c# assemblies. The library on its own works fine...
10
8203
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 obviously change once the program's fully built to actually do something, but for testing, it works). The only code I added to the service is below:
7
1500
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, but it looks like tlbimp has imported the call in a way that I can't figure out how to get my data in. SDK: VARIANT_BOOL ReadMemory(unsigned char* Data, long DataSize); IL file:
4
1687
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 expose the regex function to my old legacy application built with some tools that runs a VM with capability to access windows native DLL via declaration syntax like public int function setRegexp(String argRegexp) alias "ClassIeString.setRegexp"
0
917
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 only: AutoWrap(DISPATCH_METHOD, NULL, app, L"ShowApp", 3, sStartupParam, sDomain, sUser); The return value from pIDispatch->Invoke is DISP_E_EXCEPTION. Since excepinfo.wCode == 0, excepinfo.bstrDescription is "Application-defined or
11
11529
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 function whether i click the link then i tried this (using forms)
0
8759
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9251
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9017
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8963
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7872
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6588
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4433
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3125
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2453
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.