0

I'm new with javascript, can someon please point me in the right direction to accomplish the following code ?

I have a page to automatically log me in into websites for work, but i'm searching a way to have the login credentials being either read from a ini file, or just by using document.write so its easer to pass and change these credentials in my HTML that hase a lot of these buttons.

<script language="javascript">


var username = "firstusername";
var password = "firstpassword";


<!-- link -->
<form action="***************" method="post"  target="_blank">
<p>
<input type="hidden" name="HdnCallingProgram" value="login"/>
<input type="hidden" name="HdnAction" value="Login"/>
<input type="hidden" name="txtUserId" value="document.write(username)"/>
<input type="hidden" name="txtPassword" value="document.write(password)"/>
<input type="hidden" name="chkRemember" value="1"/>
<a class="button1" title="Bij fout aanmelden : gebruik browser back button en terug op knop klikken"  onclick="parentNode.parentNode.submit()">Cafe</a>
</p>
</form>


</script>

Thanks for reading this!

1 Answer 1

1
<form action="***************" method="post"  target="_blank">
    <p>
        <input type="hidden" name="HdnCallingProgram" value="login"/>
        <input type="hidden" name="HdnAction" value="Login"/>
        <input type="hidden" id="txtUserId" name="txtUserId" value=""/>
        <input type="hidden" id="txtPassword" name="txtPassword" value=""/>
        <input type="hidden" name="chkRemember" value="1"/>
        <a class="button1" title="Bij fout aanmelden : gebruik browser back button en terug op knop klikken"  onclick="this.parentNode.parentNode.submit()">Cafe</a>
    </p>
</form>

<script type="text/javascript">
var username = "firstusername";
var password = "firstpassword";

document.getElementById('txtUserId').value = username;
document.getElementById('txtPassword').value = password;
</script>
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks alot, that works perfect!, i do have a lot of elementid's in my page, does anyone know if this could be done with a readfrom file aswell?
Of course yes, but I don't know what file are you talking about. With ajax you can read file from server and parse it in script...
Oke, so the file i was refering to should be stored localy next to my html page, i'm hoping there could be a easer way to just "insert" variables into my code so the username and passwords could be read and inserted. Again your answer did the trick perfectly another way could save me lots of time :)
"stored localy" - It can be a little problem, because security reasons Ajax not working at localhost, but still you can use JS file. Add this, before script: <script type="text/javascript" src="file_to_read.js"></script> and in this file: window.storedData = {username: "firstusername", password: "firstpassword"}. To read data write: document.getElementById('txtUserId').value = storedData.username;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.