By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,652 Members | 1,842 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,652 IT Pros & Developers. It's quick & easy.

Checking Password

Vasuki Masilamani
P: 18
Hi, Please find the simple code below for checking password.

<HTML>
<Body>
<h2>Checking the Password</h2><br><hr>

<Form name=form1>
Enter the Password:
<Input type=password name=text1>
<br>
<Input type=button name=button1 value="Check">
<br><hr>

<h2>Changing the Password</h2><br><hr>
Enter the New Password:
<Input type=password name=text2>
<br>
<Input type=button name=button2 value="Change">
<br>
</Form>
<Script language="vbscript">
dim pass,a
pass="rajeev"
Sub button1_Onclick()
if (Form1.text1.value=pass)then
msgbox "Password Correct"
else
msgbox "Password Incorrect"
endif
End Sub

Sub button2_OnClick()
if (Form1.text2.value<>pass)then
msgbox "Password Changed"
else
msgbox "Invalid Password"
endif
End Sub
</Script>
</Body>
</HTML>

This code is not working.. I dont know what mistake i have done. Please help me in solving this problem.. Thanks in advance..

Thanks,
Vasuki
Apr 9 '08 #1
Share this Question
Share on Google+
1 Reply


jeffstl
Expert 100+
P: 432
Hi, Please find the simple code below for checking password.

<HTML>
<Body>
<h2>Checking the Password</h2><br><hr>

<Form name=form1>
Enter the Password:
<Input type=password name=text1>
<br>
<Input type=button name=button1 value="Check">
<br><hr>

<h2>Changing the Password</h2><br><hr>
Enter the New Password:
<Input type=password name=text2>
<br>
<Input type=button name=button2 value="Change">
<br>
</Form>
<Script language="vbscript">
dim pass,a
pass="rajeev"
Sub button1_Onclick()
if (Form1.text1.value=pass)then
msgbox "Password Correct"
else
msgbox "Password Incorrect"
endif
End Sub

Sub button2_OnClick()
if (Form1.text2.value<>pass)then
msgbox "Password Changed"
else
msgbox "Invalid Password"
endif
End Sub
</Script>
</Body>
</HTML>

This code is not working.. I dont know what mistake i have done. Please help me in solving this problem.. Thanks in advance..

Thanks,
Vasuki
Are you using Internet Explorer?

You have written local vbscript here that will compile and execute on the browser of the user. IE is built to handle local vbscript, other browsers are not I think.

Also you do not have any reference to your events on your form controls.

You need to use either onclick on your button control or onsubmit on the form tag control.

Expand|Select|Wrap|Line Numbers
  1. <Input type=button name=button1 value="Check" onclick="MySub">
  2.  
If you are talking about build an classic ASP page that executes on a server however vbscript will work but it will not be event driven like you have here. Only javascript will handle local events that return msg boxes across multiple browsers.

If you need to use VB to handle your data and events you will need to do it by submitting the form back to a .asp page on the server to handle your validations.

Expand|Select|Wrap|Line Numbers
  1. <form name="form1" method="post" action="MyHandlePage.asp">
  2.  
The action page will be requested when the user clicks a submit button.

From there you can get values from the text boxes with the request.form syntax.

Expand|Select|Wrap|Line Numbers
  1. dim MyVar
  2. MyVar = request.form("text1")
  3. if MyVar = Pass then
  4.      'correct password
  5. end if
  6.  
To understand form submission for ASP and VB better you should go here.
http://www.w3schools.com/ASP/asp_inputforms.asp
Apr 9 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.