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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBS auto fill and submit

Status
Not open for further replies.

HyDrOz

IS-IT--Management
Aug 25, 2011
3
0
0
US
I'm new to coding and I have a question,

I got an internal web application "Third Party" called Touch and Go it's a electronic management board.

I am wanting a vbs script to open, enter your user name and password and log in automatically when a PC user signs in.

I have it to the point to where it will launch the website, It will input the user name and password. however I cannot get it to submit.

*******This is the code to the software.*********

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "<HTML>
<HEAD>
<link REL="SHORTCUT ICON" HREF=" >
<TITLE>Touch N' Go Internet Edition Login</TITLE>
<script type="text/JavaScript">
<!--
function setfocus(){
document.logform.lname.focus();
if(document.location != "document.location = "}
}
function setcookie() {
document.cookie = "TNG=x" ; domain="192.*.*.*";
}
setcookie();
// End -->
</SCRIPT>

<SCRIPT type="text/JavaScript">
<!-- Begin
var thecookie;
var userlevel;
var usernumber;
var usersplit;
function readlevel() {
var level;
thecookie = document.cookie;
level = thecookie.split("+");
usersplit = level[0].split("=");
userlevel = level[1];
usernumber = usersplit[1];
usergroup = level[2];
}
// End -->
</SCRIPT>
<SCRIPT type="text/JavaScript">
<!-- Begin
function formHandler(form){
var URL = document.adminjavaform.admin.options[document.adminjavaform.admin.selectedIndex].value;
window.location.href = URL;
}
function reportHandler(form){
var URL = document.reportform.report.options[document.reportform.report.selectedIndex].value;
window.location.href = URL;
}
function srch(form){
var usr = document.search.searchtext.value;
window.location.href = " usr + ".htm";
}
function intng(){
status.value="0";
}
function outtng(){
status.value="0" ;
}
// End -->
</SCRIPT>
</HEAD><BODY leftmargin="0" topmargin="0" onload="setfocus();" bgcolor ="White">
<table width = "100%" bgcolor="#708090" cellpadding="0" cellspacing="0" border="0" ><tr><td height="20"><a href=" Alt="Touch N' Go" SRC="/graphics/TNGcorp.gif" border="0"></a></td></tr></table>
<table height="30" hspace="0" vspace="0" background=" border="0" cellpadding="0" cellspacing="0" width="100%" >
<tr><td class="head" valign="middle" align="left">
<INPUT type="Image" onClick="history.back()" Name="imgback" SRC=" border="0" ALT="Back|" Title="Back " ><INPUT type="Image" onClick="history.forward()" Name="imgFwd" SRC=" border="0" ALT="Forward|" Title="Forward " ></td><td class="head" valign="middle" align="left"><b>Touch N' Go Login</b></TD>
<td valign="middle" align ="right">
<font face="Arial, Helvetica, sans-serif" size="-2" color="black">
Thursday 25 August, 2011</font></td>
</tr></table>

<FORM action="" Method="POST" name="logform">
<table border="0" width="300">
<INPUT type="hidden" name="TNGpage" value="TNGLogin">
<INPUT type="hidden" name="ipaddress" value="192.*.*.*" >
<tr>
<td width="120"><font face="Arial,Helvetica,Sans Serif" size=2>Login Name: </td><td width="100"><font face="Arial,Helvetica,Sans Serif" size=2><INPUT type="Text" tabindex="1" id="lname" name="lname" size="20"</td>
</tr><tr>
<td width="120"><font face="Arial,Helvetica,Sans Serif" size=2>Password: </td><td width="100"><font face="Arial,Helvetica,Sans Serif" size=2><INPUT tabindex="2" type="password" id="pword" name="pword" size="20"</td>
</tr>
</table>
<INPUT type="Submit" VALUE="Submit Your Login" >
<INPUT type="Reset" VALUE="Clear This Form">
</form>
<table height="30" hspace="0" vspace="0" background=" border="0" cellpadding="0" cellspacing="0" width="100%">
<td>Leave both blank for guest access</td></tr></table>

<A HREF=" SRC=" border="0"></a>
</BODY>
</HTML>

********This is the code that I am using in my VBS Script.*******

WScript.Quit Main

Function Main

Set IE = WScript.CreateObject("InternetExplorer.Application", "IE_")
IE.Visible = True
IE.Navigate " Wait IE
With IE.Document
.getElementByID("lname").value = "My Username"
.getElementByID("pword").value = "My Password"

Not Sure What To Put Here To Submit The Form?

End With
End Function



Sub Wait(IE)
Do
WScript.Sleep 500
Loop While IE.ReadyState < 4 And IE.Busy
Do
WScript.Sleep 500
Loop While IE.ReadyState < 4 And IE.Busy
End Sub

Sub IE_OnQuit
On Error Resume Next
WScript.StdErr.WriteLine "IE closed before script finished."
WScript.Quit
End Sub

I have tried adding send {ENTER} key but it just opens a new webpage.

Any help would be very much Thankful.

HyDrOz.
 
You can access an HTML object simply by using it's id. Give the form an id and then call the submit method

<FORM action="" Method="POST" name="logform" [red]id="logForm"[/red]>

Code:
logForm.submit

OR

This method make more sense to the coder.
Code:
set objElement = document.getElementByID("logForm")
objElement.submit

-Geates

"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Geates,

Thank you for the response,

I don't know how this software is creating its web pages it's an access database and it creates a file such as 000000.htm and that htm does not exist in its working directory. So with this said I can not ad the ID to Submit. It there any other way to make this submit with out the ID or can you tell me how this is generating the same htm pages with out the .htm page in the working directory?

Please Excuse my ignorance's on this matter as I try to understand the logistics of how to make this work for me.

Hydroz
 
yep! .getElementsByTagName().

Code:
[green]'get all the first forms in the HTML[/green]
set objForms = IE.document.getElementsByTagName("form")

[green]'get the first form (index of 0)[/green]
set objForm = objForms(0)

[green]'iterate objForm field[/green]
for each objField in objForm
   [green]'if the field is of type "submit" then Click it[/green]
   if (objField.type = "submit") then
       objField.Click
   end if
next

-Geates




"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top