Ask coding questions

← Back to all posts
I have a question on how to add multiple users to the html code.
Big1shaq (0)
<html> <head> <script> function Login(form) { username = new Array("big shaq"); password = new Array("1234"); page = "hello" + ".html"; if (form.username.value == username[0] && form.password.value == password[0] || form.username.value == username[1] && form.password.value == password[1] || form.username.value == username[2] && form.password.value == password[2] || form.username.value == username[3] && form.password.value == password[3] || form.username.value == username[4] && form.password.value == password[4] || form.username.value == username[5] && form.password.value == password[5] || form.username.value == username[6] && form.password.value == password[6] || form.username.value == username[7] && form.password.value == password[7] || form.username.value == username[8] && form.password.value == password[8] || form.username.value == username[9] && form.password.value == password[9]) { self.location.href = page; } else { alert("Either the username or password you entered is incorrect.\nPlease try again."); form.username.focus(); } return true; } </script> </head> <body bgcolor="#eeeeee"> <form> <br> <center> <h4><b>Hello</b><h4> <h5>Username: <input type="text" name="username" style="background:#bfbfbf;color:#212121;border-color:#212121;" onFocus=" = '#ffffff';" onBlur=" = '#bfbfbf';"> <br> Password: <input type="password" name="password" style="background:#bfbfbf;color:#212121;border-color:#212121;" onFocus=" = '#ffffff';" onBlur=" = '#bfbfbf';"> <br> <input type="button" value="Login" onClick="Login(this.form);" style="background:#bfbfbf;color:#000000;border-color:#212121;" onMouseOver=" = '#404040';" onMouseOut=" = '#000000';" onFocusr=" = '#404040';" onBlur=" = '#000000';"></h5> <p1></p1></center> </form> </body> </html>
Answered by Vandesm14 (2217) [earned 5 cycles]
View Answer
CBlockSurprise (17)

I think i kind of cleaned up the code, and added a bit of my stuff. I hope this is what you need. REPL

Big1shaq (0)

@CBlockSurprise How to you add different accounts, I see the comment in the code but I am still not sure how to add them. Thank you for everything!

Vandesm14 (2217)

All you have to do is go to script.js and add new items to arrays "username" and "password". I fixed the formatting for the JavaScript as well.

Please mark this as answered if I helped your problem 👍

Big1shaq (0)

@Vandesm14 Thank you so much! This was very helpful! :)

PYer (3254)

You should link a repl so its easier to read and edit. That way, we can help you much easier.

Big1shaq (0)

@PYer I added the link! All help is welcome! (And I also found this code on a website) Also sorry if I am being hard to work with because this is my first time asking for help on repl.