By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,262 Members | 1,161 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,262 IT Pros & Developers. It's quick & easy.

typing in string values in html form fields

100+
P: 553
Hi

I am trying to write a code in HTML , maybe will use javascript if required. The code will open a webpage and type in username and password in the fields automatically and click the submit button.

The page i wish to work on put the cursor in the first field by default.

So i just need to type in the string values into these fields.

Please help as to how to proceed. Is it possible to do it in HTML alone?

Thansk a lot

Qi
Dec 23 '08 #1
Share this Question
Share on Google+
16 Replies


gits
Expert Mod 5K+
P: 5,352
i doubt that this could be done without javascript ... you need to focus() the fields what you could do with simple javascript.

kind regards
Dec 23 '08 #2

drhowarddrfine
Expert 5K+
P: 7,435
Yes. Javascript must be used.
Dec 23 '08 #3

100+
P: 553
Thanks a lot for answers

Could anyone direct me how to do it in javascript.

I know javascript to beginners level. As i said in my post, when the webpage opens, the cursor is in the right field already. Now how to type in something in that field. What javascript method shall i use?

Also, just in case, whats the function to bring focus onto a different field, is it just focus() ?

Thanks
Qi
Dec 23 '08 #4

gits
Expert Mod 5K+
P: 5,352
just one more question before we proceed. is that page where you want to have the field 'autofilled' from your domain? what is the purpose of that all ... because in case you need to fill in values across domains then i just have to say that this would be only possible with additional serverside handling ...

in case you need more information regarding that ... then you should ask a mod in the html-forum to move this thread for you over to the JavaScript-forum ... or just post a new one there ... so that other users may find that such problems involve JavaScript at least.

kind regards
Dec 23 '08 #5

100+
P: 553
yes the page is not in my domain, its an external page (customer logon page of my internet.service provider)

i was thinking of copying and saving all the source code of that page and then make changes , additions to get this done.... and when it will have been done, i will click on the saved file (it will be a HTML file) , and the page will open up with the fields filled in. could this be done?

I have read the source code of that page, it is only HTML with javascript.

Thanks
Qi
Dec 23 '08 #6

acoder
Expert Mod 15k+
P: 16,027
Moved to JavaScript forum

--Moderator.

If all you want to do is have the fields auto-filled, you can use the feature in your browser (where it remembers the password), or use a program like Roboform.
Dec 23 '08 #7

gits
Expert Mod 5K+
P: 5,352
in this case you just need to use the local copy and write the username and password to the value attrib of the corresponding textfields ... and the only thing you need to do would be to click the submit button ... you could even trigger a function onload of the local-page that submits the form (you may use the submit() function of the form-element) ... may be additionally you need to adapt some urls from relative to absolute ones ...

kind regards

PS: or use acoders hint and just use the browser feature ...
Dec 23 '08 #8

Expert 100+
P: 173
To execute the Javascript it would need to be run on the page in question. Since this is not one of your pages you would need to inject the Javascript. The easiest way to do this is to write a userscript and use GreaseMonkey for Firefox. An alternative for IE is called Trixie although I have not used this for a number of years.

If the information is posted on the page using a GET request the easier method of doing this would be submit a request with the information already within the request e.g "www.some.domain.com/login.aspx?username=foo&password=bar".

If the page uses a POST request then you would need to make a HTTP POST request. Although this also may not work if the page does validation to ensure that the request was submitted directly from their page.
Dec 24 '08 #9

gits
Expert Mod 5K+
P: 5,352
when the page runs locally you could easyly modify the javascript in it without any injection or whatever. the page just needs to ensure that the form is send to the correct address ... or do i miss something here? ... besides any validation logic the serverside might do ... of course.

kind regards
Dec 24 '08 #10

Expert 100+
P: 173
I thought that the pages were not local as the OP said that they were not on their domain

yes the page is not in my domain, its an external page (customer logon page of my internet.service provider)
I suppose that this could be run through a "javascript:..." entered in the location bar.

I could also be totally misunderstanding and talking gibberish :)
Dec 24 '08 #11

100+
P: 553
Thanks all for replies

The webpage in question doesn't have 'remember me' kind of thing on it , not does IE remembers anything .. I think Firefox has extra capability to remember ID/Passwords and it may or maynot work in my case but i dont want to use Firefox.

Further to your technical replies, could anyone direct me to the functions i needto write that will fill in the fields automatically.

Before we could talk about writing code, how would i determine the fields' name on that page? I think Dreamweaver tell syouwhen you click on any object, it is highlighted in the source code which object you click on.

I am not willing to buy or download heavy downloads of Dreamweaver, so i would be thankful for someones further help in it.

As to Roboform, is it safe, i mean passwords saved in it can be stolen all at once? If yes, is there any freeware you similar to this?

My preference is to write my own code instead, so assuming i know the name of the fields on that page. I need to use onPageLoad or onPageOpen (are there any such functions in javascript?) , if yes what r these?

Thanks
Qi
Dec 25 '08 #12

gits
Expert Mod 5K+
P: 5,352
if you have saved the file locally you just need a texteditor to view the sourcecode ... now search for something like:

Expand|Select|Wrap|Line Numbers
  1. <input type="text" name="some_name_of_the_user_field"/>
  2.  
there you just need to add the value like this:

Expand|Select|Wrap|Line Numbers
  1. <input type="text" name="some_name_of_the_user_field" value="foo"/>
  2.  
do the same for the passwordfield and use your credentials. now save it and open it in the webbrowser ... now you should see foo typed in. now press the submit button and see whether it works or not. in case it works then you could add a function that is called onload of the page and that submits the form instantly. but first try to find the fields and check whether it would work locally.

kind regards
Dec 25 '08 #13

gits
Expert Mod 5K+
P: 5,352
@phvfl
i thought in post #6 the OP told that he wanted to just save the page locally and modify it to his/her needs?

kind regards
Dec 25 '08 #14

100+
P: 553
Thanks for replies

I have found the fields name with your help and have populated fields' value also.

Now before i write onLoad function, i am facing another problem:

When i manually click on 'Submit' button, nothing happens. The reason is that i have saved the source code of the original page on my C drive and when 'Submit' button is clicked, this URL is loaded:

Expand|Select|Wrap|Line Numbers
  1. C:\Documents and Settings\Private\Desktop\Login.aspx
  2.  

The page uses POST method. When i open the URL, here
http://0.0.0.0/SelfCare/Dashboard.aspx ----0.0.0.0 is not real IP

I have found this from the code:
<form name="form1" method="post" action="Login.aspx" id="form1">

How can i make the submit button to open the actual page ?

Thanks
Qi
Dec 26 '08 #15

gits
Expert Mod 5K+
P: 5,352
you need to replace the relative url to where the data are to be send with the absolute one ... that would be the url from where you saved the page and add this before the aspx-file (where the form's action is specified). but as was said already - in case the server does any validation to check where the data was sent from it could be that it will not work ...

kind regards
Dec 26 '08 #16

acoder
Expert Mod 15k+
P: 16,027
In that case, i.e. where that checking does take place, you can use a user-script as mentioned earlier.
Dec 29 '08 #17

Post your reply

Sign in to post your reply or Sign up for a free account.