hey all.. i want to make a simple login page. I have prepared two textfield.
<input type="text" id="user">
<input type="password" id="password">
<input type="button" id="go">
i want after click #go script can check:
if #user value != "admin"
then #password value != "qaubuntu"
will show and JS alert. but if data same, will show some hidden . can you show me how to do that?
asked Oct 20, 2010 at 7:22
klox
2,09311 gold badges39 silver badges66 bronze badges
-
1So i'll start my comment with the last two words you ended your answer with: Please help - me understand what you actually want. Oh, in proper English. Use Google Translate for all we care.Jacob Relkin– Jacob Relkin2010年10月20日 07:27:08 +00:00Commented Oct 20, 2010 at 7:27
2 Answers 2
$(function() {
$('#go').click(function() {
if($('#user').val() !== "admin" || $('#password').val() !== "qaubuntu") {
alert('Invalid login');
return false;
} else {
return true;
}
});
});
that's the quick fix (assuming you're just playing around). But you should never do it like this for a few reasons:
- Anyone with half a brain can look at your JavaScript and see what the id/pw is
- I always think it's better to do the user authentication at the server side
- Probably a million others, it's so insecure it hurts
but for the purpose of this answer I'm assuming you're just practising with jQ.
answered Oct 20, 2010 at 7:27
EMMERICH
3,4842 gold badges21 silver badges15 bronze badges
Sign up to request clarification or add additional context in comments.
2 Comments
tomsseisums
+1, this is huuge security problem! But yes, the answer should do what has been asked.
klox
yups..this is for the starter..could you give me some script that you mention at no.2?
this is in jquery, when clicking on button #go check the login data
$('#go').bind('click',function()
{
if($('#user').val() == 'admin' && $('#password').val() == 'qaubuntu'))
//ok do what you need
else
alert('username or password not valid');
});
answered Oct 20, 2010 at 7:27
Dalen
9,0264 gold badges49 silver badges53 bronze badges
Comments
lang-js