Link to home
Create AccountLog in
Avatar of Oliver Wastell
Oliver WastellFlag for United Kingdom of Great Britain and Northern Ireland

asked on

How can I programmatically click on an image button to submit a form

Hi Experts,

I am using the IE web browser object in a MS Access form to automatically log into my online telephone account, although I am having a problem submitting the form.  I am using the following visual basic code:

    WebBrowserCallagenix.navigate "http://www.callagenix.com/"
    DoEvents: DoEvents: DoEvents
    Do While WebBrowserCallagenix.Busy   'wait until the page loads by looping
      DoEvents
    Loop
    Set doc = WebBrowserCallagenix.Document    'access the document properties
    DoEvents
    Do While WebBrowserCallagenix.Busy
        DoEvents
    Loop  
    returnValue = FillForm("pAccountCode", "my_account", False)
    returnValue = FillForm("pPassword", "my_password", False)
    WebBrowserCallagenix.Document.Forms("cgxlogin").submit

The above code enters the account name and password into the appropriate fields but I then receive the following error message:
 'Object doesn't support this property or method'

I think the issue is to do with the fact that the form uses the post method and/or an image for the login button, but this doesn't help me figure out how to submit the form.

Any ideas?

Here is the html code for the form itself:


<form name="cgxlogin" target="_top" id="cgxlogin" method="post" action="https://secure.callagenix.com/Pages/login/login.asp">
<label for="Account">Account</label><br />                    
<input name="pAccountCode" type="text" class="formfieldreg" id="pAccountCode" size="10" maxlength="10" />
<br />
<label for="Password">Password</label><br />                    
<input name="pPassword" type="password" class="formfieldreg" id="pPassword" size="10" maxlength="10" />
<input type="hidden" name="Submit" value="Login" />
<input name="imageField" type="image" id="login-button" src="images/new/button-login.gif" alt="Login" />
<a href="/registration/register.asp" title="Create New Account"><img src="images/new/button-reg.gif" alt="Register" width="76" height="26" border="0" /></a>
</form>

Open in new window

Avatar of Mike_Carroll
Mike_Carroll
Flag of Ireland image

There are a variety of ways to do this and there are details here http://www.javascript-coder.com/javascript-form/javascript-form-submit.phtml
Avatar of Oliver Wastell

ASKER

Hi Mike, thank you for your comment.  I should have made it clear that the form is on a third party website (www.callagenix.com) so I cannot alter the source html.  The code for the form used is provided in the original question posted and this I cannot change.  What I need to know is how can I submit it by interacting with the Microsoft browser's DOM.

Any thoughts?
Hi

I programmed a solution to this in php, and basically what you have to do is to call the click event of the button name, i.e. loop through all the elements to get the button's name.

hth
Hi Paisleym, I have tried the following:
  WebBrowserCallagenix.Document.Forms("cgxlogin").elements("imageField").Click
but as it is not a button and is instead an image I get the following error message.
'Object variable or With block variable not set'
Clicking on the image in the browser control does submit the form though.
SOLUTION
Avatar of paisleym
paisleym
Flag of Australia image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
SOLUTION
Avatar of hes
hes
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
ASKER CERTIFIED SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account