Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WebBrowser Submit Problem 3

Status
Not open for further replies.

Error7

Programmer
Jul 5, 2002
656
GB
Hi

I'm using the following to activate the submit button on a webpage:

WebBrowser1.Document.All("submit").Click

But I get an error "Object variable or With block variable not set."

Can anybody help me with this, please.

Alan

[gray]Experience is something you don't get until just after you need it.[/gray]
 
>WebBrowser1.Document.All("submit").Click
If "submit" is the element's type, then it is the wrong syntax. You furnish its id or name as parameter.
 
This is the line from the html source:

dstr += '<p><input TYPE="button" VALUE="Sync system time to PC" onClick="SubmitTimeAndDate()"></p>\n';

I thought that if TYPE="button" then "WebBrowser1.Document.All("submit").Click" would activate it.

Can you help any further with this. I am struggling.

Alan

[gray]Experience is something you don't get until just after you need it.[/gray]
 
<input TYPE="button" VALUE="Sync system time to PC" onClick="SubmitTimeAndDate()" id="Submit">
 
Thanks VBakias, but I'm not sure what you are telling me?

Alan

[gray]Experience is something you don't get until just after you need it.[/gray]
 
dstr += '<p><input TYPE="button" VALUE="Sync system time to PC" onClick="SubmitTimeAndDate()" id="Submit"></p>\n';
 
Sorry, I should have explained better, I want to put the code behind a command button on my form so that when I click my command button it activates the submit button on the web page.

Command1_click()
"WebBrowser1.Document.All("submit").Click"
End Sub

Alan

[gray]Experience is something you don't get until just after you need it.[/gray]
 
aaa okk,

Command1 code:
WebBrowser1.Document.All("myName").Click


This is button in browser:
<input type="button" value="buttonCaption" name="myName">


This works, tested.
 
<input TYPE="button" VALUE="Sync system time to PC" onClick="SubmitTimeAndDate()" name="Submit">

and

WebBrowser1.Document.All("Submit").Click
 
But this is where I started...

"WebBrowser1.Document.All("Submit").Click"

Gives the error "Object variable or With block variable not set."

Alan

[gray]Experience is something you don't get until just after you need it.[/gray]
 
OK, thanks.

Unfortunately I can't test it until I get back to work in the morning (GMT = 09:00).

But can I just clarify what I'm trying to achieve.

I am browsing to a webpage on a remote server. I have no control over the source code behind the webpage. I can only read it.
The webpage has 2 buttons. Button 1 is the submit button. Button 2 is for loading a Help page.

If I manually click the submit button it updates the time and date on the remote server with the values from the local PC.

My programme will connect to all remote servers, several hundred of them, once a week and sync the time and date.

I have already got as far as connecting to each server automatically and loading the appropriate webpage but I have been unable to figure out how to click the submit button programmatically without getting the error.

(my example of putting the code behind a command button on the form was just to simplify my explanation of what I am trying to do.)

The code will actually be included in the NavigateComplete Event of the VB WebBrowser when I overcome the problem with the error.

I hope I am explaining myself ok.

Alan

[gray]Experience is something you don't get until just after you need it.[/gray]
 
I'm not getting anywhere with this. Perhaps I just can't see the wood for the trees.

This is the whole of the source from the webpage that I'm connecting to.

------------------------------------------------------------
<html>
<head>
<title>TIME & DATE OPTIONS</title>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<meta description= "modified 2/10/2000 JB">

<SCRIPT LANGUAGE="JavaScript" SRC="../frmpages/defines.js"></SCRIPT>

<script LANGUAGE="JavaScript">
<!--

var now_time = 1122460542;
var gps_time = 0;
var time_offset = 3600;
var locale = 'BST';
var features=112;

var TITLE = '<CENTER><BR><FONT SIZE=+2 FACE="Arial">Time & Date Options</FONT></CENTER>';

function BuildCGIURL()
{
Now=new Date()
var offset = Now.getTimezoneOffset();
var utc_offset;
var julian;
var dstr = ""

julian = Math.round(Now.getTime()/1000);
utc_offset = -(offset*60);
// build a .frm name based on the location pathname
with (location)
dstr += pathname.substring(pathname.lastIndexOf("/"),pathname.indexOf("."))+".frm";
dstr += "?";

dstr +='utc_offset=' + utc_offset + '&current_julian=' + julian;
return dstr;
}


function SubmitTimeAndDate()
{

var CGIURL;

CGIURL = BuildCGIURL();
self.location=CGIURL;

}

function formset()
{
Now=new Date()
var offset = Now.getTimezoneOffset();
document.disform.time_val.value = Math.round(Now.getTime()/1000);
document.disform.time_offset.value = -(offset*60);
document.disform.opname$.value = ""
}

function show_time_pc(julian)
{
var time = new Date();
var offset = time.getTimezoneOffset();
var str = "";

if (julian > 0) {
time.setTime((julian * 1000) + (offset*60000));
}
str = time.toLocaleString()
return str;
}

function show_offset_pc()
{
var time = new Date();
var offset = time.getTimezoneOffset();
var str = "";

str = -(offset)
return str;
}

function show_time_target(julian)
{
var time = new Date();
var offset = time.getTimezoneOffset();
var str = "";

if (julian > 0) {
time.setTime((julian * 1000) + (time_offset*1000) + (offset*60000));
}
str = time.toLocaleString()
return str;
}

function show_time_gps(julian)
{
var time = new Date();
var offset = time.getTimezoneOffset();
var str = "";

if (julian > 0) {
time.setTime((julian * 1000) + (offset*60000));
}
str = time.toLocaleString()
return str;
}

function show_offset_target()
{
var time = new Date();
var str = "";
str = time_offset/60
return str;
}

function show_help()
{
HELP=window.open('help_timedate.html','HELP', 'resizable=yes,toolbar=0,location=0,status=0,menubar=0,scrollbars=0,screenX=332,screenY=0');
}

//-->
</script>
</head>

<body bgcolor="#FFFFF0" background="/webpages/images/back.jpg">

<script>
<!--
var dstr=""

dstr += '<p>&nbsp</p>\n';
dstr += '<FORM NAME="DateTimeOptions" ACTION="' + location.protocol + '//' + location.host + '/timedate.frm" METHOD="GET">\n';
dstr += '<CENTER>';
dstr += '<p>&nbsp</p>\n';
dstr += '<p>Current System time : ' + show_time_target(now_time) + '</p>\n';
dstr += '<p>System GMT offset in mins : ' + show_offset_target() + '</p>\n';
if (locale)
dstr += '<p>Current timezone : ' + locale + '</p>\n';
dstr += '<p>&nbsp</p>\n';
if (features & SYSTEM_GPS)
{
dstr += '<p>Current GPS time : ' + show_time_gps(gps_time) + '</p>\n';
dstr += '<p>&nbsp</p>\n';
}
dstr += '<p>Current PC time : ' + show_time_pc(0) + '</p>\n';
dstr += '<p>PC GMT offset in mins : ' + show_offset_pc() + '</p>\n';
dstr += '<p><input TYPE="button" VALUE="Sync system time to PC" onClick="SubmitTimeAndDate()"></p>\n';
dstr += '</CENTER>';
dstr += '<p><div align=right><input TYPE="button" VALUE="Help" onClick="show_help()"></div></p>\n';
dstr += '</FORM>\n';
document.write(TITLE);
document.write( dstr );


//-->

</script>
<body bgcolor="#FFFFF0" background="/webpages/images/back.jpg"></body>
</html>

------------------------------------------------------------

I just need to click the submit button programatically so that the time and date on the remote server is synchronised to my local PC.

"WebBrowser1.Document.All("Submit").Click" gives the error "Object variable or With block variable not set."

Can anybody help, please please please.

Alan

[gray]Experience is something you don't get until just after you need it.[/gray]
 
>[tt]dstr += '<p><div align=right><input TYPE="button" VALUE="Help" onClick="show_help()"></div></p>\n';[/tt]
Give it a unique name/id.
[tt]dstr += '<p><div align=right><input TYPE="button" VALUE="Help" [blue]id="submitid"[/blue] onClick="show_help()"></div></p>\n';[/tt]
Then call it over.
[tt]WebBrowser1.Document.All("[blue]submitid[/blue]").Click[/tt]
 
Thanks tsuji, but I'm still not clear. (yes, I'm a thicko)

I don't think I can give it a unique ID. I'm only reading the source of the webpage. I can't write to it or change it.

Alan

[gray]Experience is something you don't get until just after you need it.[/gray]
 
> I can't write to it or change it
Then try this.
[tt] WebBrowser1.Document.DateTimeOptions.All.Tags("input")(1).Click[/tt]
 
tsuji, you are a STAR!!!

That does exactly what I wanted. Thank You. Thank You. Thank You.

Alan

[gray]Experience is something you don't get until just after you need it.[/gray]
 
VBakias, if that was a hint then o.k. thanks for your efforts too.

I didn't mean to neglect you.

Alan

[gray]Experience is something you don't get until just after you need it.[/gray]
 
That was not a hint or star-asking post. I think i gave you earlier the solution (adding something in html code). To be sure i created a page with a button and a js alert so as to test it before i post.

I don't win something if i have stars or not a single one. So i give you back the star.
 
VBakias wrote
>I don't win something if i have stars or not a single one.
That's true and I am sure members at the receiving end of your advice would appreciate it.
>So i give you back the star.
That's not an effective and nice gesture... I hope bigalbigal is not frustrated by being so reciprocated to his kind consideration. If I were him, I would be quite taken aback. I'm sure he'll get over it quick enough.

While you're still on the topic, [1] "submit" is never a good name/id given to an element in particular input elements; and [2] if one cannot edit the wed page, one cannot; and there are more than enough ways to refer to the specific element than a straightforward "all".

- tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top