montypy
asked on
How can I pass a string to a document.forms?
Hello
How can I pass a string to a document.forms[1][0] and submit using Chrome DevTools?
How can I pass a string to a document.forms[1][0] and submit using Chrome DevTools?
You mean
(function() {var LF = document.getElementById("u ser_name") ; LF.value="Bart"; LF.form.submit()})()
or
(function() {var F = document.forms[1]; LF = F["log"]; LF.value="Bart"; F.submit()})()
(function() {var LF = document.getElementById("u
or
(function() {var F = document.forms[1]; LF = F["log"]; LF.value="Bart"; F.submit()})()
In DevTools goto the Console tab and there you can enter and run any js commands you want.
ASKER
For this, I get :
(function() {var LF = document.getElementById("user_name"); LF.value="Bart"; LF.form.submit()})()
TypeError: Cannot set property 'value' of null
Probably there is no element with ID user_name but
This makes no sense - LF refers to element, I assume a text box, so it doesn't have a FORM
LF.form.submit
This makes no sense - LF refers to element, I assume a text box, so it doesn't have a FORM
LF.form.submit
ASKER
You were right, the element is "user_login", So now the username is submitted correctly. However, I get a new error- "TypeError: object is not a function"
. I need to submit the username and password and submit. The password element ID is "user_pass"
. I need to submit the username and password and submit. The password element ID is "user_pass"
(function() {var LF = document.getElementById("user_login"); LF.value="Bart"; LF.form.submit()})()
TypeError: object is not a function
Can you post the FORM html.
ASKER
<form name="loginform" id="loginform" method="post" _lpchecked="1">
<p>
<label>Username:<br>
<input type="text" name="log" id="user_login" class="input" value="" size="20" tabindex="10" autocomplete="off" style="cursor: auto; background-image: url(data:image/png;base64,base64c=); background-attachment: scroll; background-position: 100% 50%; background-repeat: no-repeat;"></label>
</p>
<p>
<label>Password:<br>
<input type="password" name="pwd" id="user_pass" class="input" value="" size="20" tabindex="20" autocomplete="off" style="cursor: auto; background-image: url(data:image/png;base64,bas64c=); background-attachment: scroll; background-position: 100% 50%; background-repeat: no-repeat;"></label>
</p>
<p class="submit">
<input type="submit" id="submit" value="Login »" tabindex="100">
</p>
<script type="text/javascript">
<!--
document.loginform.submit.disabled= false;
// -->
</script>
<noscript>
<p><b>ERROR: Javascript is required for this page; please enable it in your browser.</b></p>
</noscript>
</form>
Michel already gave you the correct code above (just slightly amended to target by name)
(function() {var F = document.forms['loginform']; LF = F["log"]; LF.value="Bart"; F.submit()})()
ASKER
When I enter that into the Console it does not log into the website. Also, the function does not provide a use_pass element.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks! that did it
ASKER
Thanks again for staying with me :) I really appreciate it!
If that worked then mine should have worked too had I been allowed to see the form. document.forms[1] is the SECOND form on the page, if you wanted the first one, it was document.forms[0] - I just used your information.
(function() {
var F = document.forms['loginform'], LF = F["log"], LP=F["pwd"]; // all are local vars
LF.value="Bart";
LP.value="password";
F.submit()
})();
ASKER
It does not work:
(function() {
var F = document.forms['loginform'], LF = F["log"], LP=F["pwd"]; // all are local vars
LF.value="Bart";
LP.value="password";
F.submit()
})();
TypeError: F.submit is not a function
That is because there is an object in the form that is named "submit"
<input type="submit" id="submit" value="Login »" tabindex="100">
so either that needs to be renamed or you have to click the submit button just like suggested by Gary
<input type="submit" id="submit" value="Login »" tabindex="100">
so either that needs to be renamed or you have to click the submit button just like suggested by Gary
ASKER
Open in new window