Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

JS Help - submit form


  • Please log in to reply
20 replies to this topic
soccer18soccer18
  • Members
  • 101 posts
  • Last active: Sep 12 2009 10:51 PM
  • Joined: 18 Nov 2008
here is the code for the webpage:

<table><tr valign="top"><td><label for="__ProxEasyURLd"><b>Web Address</b></label></td><td rowspan="2"><input name="ctl00$ContentPlaceHolder1$__ProxEasyURLd" type="text" id="ctl00_ContentPlaceHolder1___ProxEasyURLd" class="address_box" />
<input type="submit" class="go" value="Go" /></td></tr><tr><td><span style="font-size:9pt">(eg: facebook.com)</span></td></table>


i fill in the input box but then i dont know how to click the submit (Go) button. Im using COM to do this and i dont wanna use anything like controlclick/send.
I know this isnt a JS forum, but i dont konw where else to ask this question. if you know anything and can help me out, just post. that would be great.

Thanks. :)

tank
  • Administrators
  • 4345 posts
  • AutoHotkey Foundation
  • Last active: May 02 2019 09:16 PM
  • Joined: 21 Dec 2007
post your code?
Never lose.
WIN or LEARN.

jethrow
  • Moderators
  • 2854 posts
  • Last active: May 17 2017 01:57 AM
  • Joined: 24 May 2009
javascript: <--path to element--> .click(); void(0)
You need to find the path to the Submit Button. I use the program IE HTML Element Spy to identify and create a reference to the element.

Seatbelt99
  • Members
  • 136 posts
  • Last active: Jan 10 2012 02:55 PM
  • Joined: 08 Aug 2007
javascript:document.forms[0].submit()

That works on about 75%of sites. With out knowing the specific site I won't be able to say for sure if it will work on this one.

smikkelsen
  • Members
  • 126 posts
  • Last active: Jan 02 2014 06:38 AM
  • Joined: 24 Jun 2008
I have been on a long long long time search for a fix to this problem. I have seen and heard much about this java script in the address bar, and also the com/dom methods of doing it as taught by Tank, but have never gotten a single one of them to work.

If I were to want to open google and through java script do a search for "test" or something like that, how would I do it using your javascript code here Seatbelt99 or jethrow?

Maybe even a step further for me if you could, how would you use it to send a username and password to the login page of gmail?

I would love some help with this.

Note: Post modified to change member information per member request. ~ sinkfaze (07/07/2011)

jethrow
  • Moderators
  • 2854 posts
  • Last active: May 17 2017 01:57 AM
  • Joined: 24 May 2009
And I would love to help you. As far as searching for "test", I've never had any need or desire to do this, so I don't know for sure. However, entering a username and password for the login page of gmail would be like this:
Enter Username:
javascript: document.getElementById("Email").value="Username"; void(0)
-OR-
javascript: document.forms[0].elements[9].value="Username"; void(0)
Enter Password:
javascript: document.getElementById("Passwd").value="Password"; void(0)
-OR-
javascript: document.forms[0].elements[10].value="Password"; void(0)
Click Sign in:
javascript: document.getElementsByName("signIn")[0].click(); void(0)
-OR-
javascript: document.forms[0].elements[13].click(); void(0)
And all together:
javascript: document.getElementById("Email").value="username"; document.getElementById("Passwd").value="Password"; document.getElementsByName("signIn")[0].click(); void(0)
-OR-
javascript: document.forms[0].elements[9].value="Username"; document.forms[0].elements[10].value="Password"; document.forms[0].elements[13].click(); void(0)

Just put that code in the address bar and hit enter (change Username and Password of course). Or, use COM_Invoke(objIE, "Navigate", jscript).

Edit - I should note that in the COM function, objIE is a pointer to the Internet Explorer Object, and jscript is a variable containing the code shown above. Note - A COM function to enter the Username could also be written like this
COM_Invoke(objIE, "document.forms[0].elements[9].value", "Username")


smikkelsen
  • Members
  • 126 posts
  • Last active: Jan 02 2014 06:38 AM
  • Joined: 24 Jun 2008
That worked perfectly. Thanks so much for responding and helping.

One last question so hopefully I wont have to bother you again, how do you go about finding the element names? do you use something like windows spy, or do you search through the source code?

You also said you could use:
COM_Invoke(objIE, "Navigate", jscript)
for the same end result? Would you mind giving me a working example for this method?

Thanks again, you are a lifesaver! Everytime I ever ask anyone about this, they just bombard me with forty thousand links to threads that i've already read, so your time is much appreciated.

jethrow
  • Moderators
  • 2854 posts
  • Last active: May 17 2017 01:57 AM
  • Joined: 24 May 2009

how do you go about finding the element names?

That is actually the hardest part. As I stated above, I use a program called IE HTML Element Spy (if you use universal extractor, you can make the program portable). Or, an on-the-fly method would be to type a value in the Username Field. Then put the following in the address bar:
javascript: alert(document.forms[0].elements[0].value)
This will pop-up the value of that element. Keep increasing the index of forms[0] and elements[0] until you find the value you typed in.


Would you mind giving me a working example for this method?

COM_Init() ; Initialize COM - requires COM.ahk library

objIE := COM_CreateObject("InternetExplorer.Application")
COM_Invoke(objIE, "Visible", "True")
COM_Invoke(objIE, "Navigate", "www.gmail.com")

^j:: ; use hotkey after page has loaded
jscript = javascript: document.getElementById("Email").value="username"; document.getElementById("Passwd").value="Password"; document.getElementsByName("signIn")[0].click(); void(0)

COM_Invoke(objIE, "Navigate", jscript) 
;~OR~
;COM_Invoke(objIE, "document.getElementById[Email].value", "username")
;COM_Invoke(objIE, "document.getElementById[Passwd].value", "Password")
;COM_Invoke(objIE, "document.getElementsByName[signIn].item[0].click")

COM_Release(objIE)
COM_Term()
return

Everytime I ever ask anyone about this, they just bombard me with forty thousand links to threads

Check out the links I posted in this topic: <!-- m -->http://www.autohotke... ... highlight=<!-- m --> (7th post)

smikkelsen
  • Members
  • 126 posts
  • Last active: Jan 02 2014 06:38 AM
  • Joined: 24 Jun 2008
Great, that is very helpful thanks.

It sounds like if an input field does not have an ID and only a Name, it can't be done?

I read through your links and found the tutorial on w3schools, but I could only find the document.getElementById function.

I would think that doing document.getElementByName instead could work, but i'm having no luck with that.

Again, thanks for your help. I also downloaded IE HTML Element Spy, and it is MUCH easier than going through all the source code.



Edit:
Sorry, I actually got it to work using the form element method you mentioned instead. This is awesome! I appreciate your help once again. Some of us learn best by a little one on one help, so your time is invaluable to me.

jethrow
  • Moderators
  • 2854 posts
  • Last active: May 17 2017 01:57 AM
  • Joined: 24 May 2009
Check out <!-- m -->http://www.w3schools...bj_document.asp<!-- m -->

getElementById(""), getElementsByName("")[], getElementsByTagName("")[]
If it's Elements, it will return a collection, and you need an index. See code in previous post for clicking the Sign in button on gmail.com

tank
  • Administrators
  • 4345 posts
  • AutoHotkey Foundation
  • Last active: May 02 2019 09:16 PM
  • Joined: 21 Dec 2007
well articulated jethrow. Its nice to see someone other than me responding to these with such a good understanding. Thanks

Note: Post modified to change member information per member request. ~ sinkfaze (07/07/2011)
Never lose.
WIN or LEARN.

smikkelsen
  • Members
  • 126 posts
  • Last active: Jan 02 2014 06:38 AM
  • Joined: 24 Jun 2008
Thanks again for the help. That tutorial on w3schools was great as well.

I now have a gui working to automatically log in to all of my password protected sites using both the com library that tank has given a great tutorial on (once thinks finally click in my head, its not so overwhelming), and also using the javascript injection that you have been so kind to teach me jethrow. Thanks to both of you (tank and jethrow) for the help.

Now I have moved onto something else, and can't quite get it working, so I thought I would ask to see if it can be done.

I am trying to read the contents of an element into an ahk variable.



java=javascript: document.getElementsByName("UserName")[0];

is there a way to somehow use javascript like this to read the contents of a field into a variable?

Thanks again!

Note: Post modified to change member information per member request. ~ sinkfaze (07/07/2011)

tank
  • Administrators
  • 4345 posts
  • AutoHotkey Foundation
  • Last active: May 02 2019 09:16 PM
  • Joined: 21 Dec 2007
you are going to have to abandon your dependency and dive into COM functions for that

you will need to have an iwebbrowser2 reference demostrated in many places See the ie com tutorial(search the forum)
in this case i'll refer to the iwebbrowser2 object with a variable pwb jethrow use objIE in his example
textfromelement:=com_invoke(pwb,"document.getElementsByName[UserName].item[0].innerHTML")
in the event that its a form element your reading use value instead of innerhtml

Note: Post modified to change member information per member request. ~ sinkfaze (07/07/2011)

smikkelsen
  • Members
  • 126 posts
  • Last active: Jan 02 2014 06:38 AM
  • Joined: 24 Jun 2008
Great, thats all i needed. (for now). I do understand iwebbrowsewr2 referenc at this point, and understand that the pwb is referring to a connected instance of iwebbrowser2.

The thing I guess i'm having the trouble with though, is how, or where I can learn everything about com. (I can understand it once someone tells me what a possible syntax is with the functions, but how the crap does one go about knowing that in the first place without asking someone who just so happens to know?) I've read everything on the thread where you can download com library, but it doesn't do a good job at all about explaining the functions, or what the possibilities even are.

So to your comment:

you are going to have to abandon your dependency and dive into COM functions for that

If you are referring to my dependencies of asking others, I don't know where else to look.

So, thanks again for your time and help.

tank
  • Administrators
  • 4345 posts
  • AutoHotkey Foundation
  • Last active: May 02 2019 09:16 PM
  • Joined: 21 Dec 2007
no Sorry i was refering to the dependancy on javascript


COM is not so scary as it sounds
The tutorial i posted has links to the MSDN after a while you will just get confortable with going to the msdn and looking for avaialbe methods objects and properties
accessing the document from the iwebbrowser gives you access to DOM methods objects and properties.

Remember COM is a method for applications to communicate
Never lose.
WIN or LEARN.