0

How to submit data form without clicking a submit button

I’m trying to write a code to automatically log me into a particular website. I have successfully gotten it to enter the username/password credentials, but do not know how to get the form to then submit without me having to click the “submit” button. Is there someway to code the form to automatically submit my info (maybe by a JS function or by overwriting their html)? WEBSITE’S HTML: <form action="/home/signin?ReturnUrl=%2fappointments" method="post"> <fieldset> <div class="login-inner"> <input id="ReturnUrl" name="ReturnUrl" type="hidden" value="/appointments" /> <div class="input-container"> <span class="input-label"> <label for="Email">Email</label> </span> <input class="input" id="Email" name="Email" placeholder="Email or User Name" size="16" type="text" value="" /> </div> <div class="input-container"> <span class="input-label"> <label for="Password">Password</label> </span> <input class="input" id="Password" name="Password" placeholder="Password" size="16" type="password" /> </div> <div> <input type="submit" class="login" value="Log In" /> </div> My CODE SO FAR: var myUser = document.getElementById("Email"); myUser.value = "Username"; var myPass= document.getElementById("Password"); myPass.value = "Password"; https://code.sololearn.com/WGRX9sZ5icTK/?ref=app

7th Nov 2019, 3:25 PM
Randy
Randy - avatar
7 odpowiedzi
+ 1
What you could do is use an onkeypress event in the input box, and run a function each time that checks if the username and password is correct, if so, login. This is the lightest way I can think of approaching this.
8th Nov 2019, 5:00 PM
coddy
coddy - avatar
+ 1
thanks Coder's Crux would onkeypress still work if im trying to import the login data automatically without typing it (and running it on a tablet or phone)? also, i just found these two html attributes online that sounded like they might do something similar to your idea of onkeypress: <input type="text" oninput="myFunction()"> <input type="text" onchange="myFunction()"> Could these be other viable options? and if so, how do i program them to work in the code? (I’m only a couple weeks into coding so dont know too much about all the ins and outs)
8th Nov 2019, 8:50 PM
Randy
Randy - avatar
+ 1
javascript is client-side, meaning that when a user enters the website these files are sent to his computer as well. If you intend on using php you will need an Apache server, which is a website that runs php code. I recommend using xampp, which is a server manager which sets everything up for you. You will need to portforward and such but there are plenty of tutorials on that. If you plan on using php then, this is the workflow I suggest (search the web for these things): 1. make a php function that takes arguments username and password. 2. listen on every keypress and with javascript use something called ajax to run the php function through js, and pass the credentials to it. 3. In the php function, compare the credentials, and if they are correct, you are logged in! Of course, if using xampp instead of renting a server you will need the computer up 24/7, or at least when you're intending to use it. If you want you could even have multiple accounts, but you can go crazy and explore. msg me if you need help.
9th Nov 2019, 3:14 PM
coddy
coddy - avatar
0
All of these events should work for your code, now, I am hoping this is just a learning project, because you should never use javascript for logging in because people can just inspect page and see the password, you should use php instead. But if not, you should make a script tag andd in it you can check for passwords. I will send you ab example code soon
8th Nov 2019, 10:16 PM
coddy
coddy - avatar
0
@Coder’sCrux Oh!! Yeah, i was intending to actually use this to program an Apple Shortcut to log me in to a website 😬 Would using the javascript “post” method to interact with a website still allows others to read it thru inspection? Can i use php on someone else’s website? Thanks for your help!!
9th Nov 2019, 2:42 PM
Randy
Randy - avatar
0
Coder's Crux hmm, thats a great start. Thanks so much!!!
9th Nov 2019, 7:37 PM
Randy
Randy - avatar
0
Coder's Crux - I searched online about the JavaScript passwords and php, and just want to make one more clarification before I either quit this particular code or try learning a new language, lol. So the website I want to make a code to automatically log in to is not my website, but an already established one. Wouldn’t this mean my JavaScripted credentials are client-side only, and therefore not stored in the website or accessible to others thru inspection?
12th Nov 2019, 3:40 PM
Randy
Randy - avatar