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.
-
<Input type=button name=button1 value="Check" onclick="MySub">
-
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.
-
<form name="form1" method="post" action="MyHandlePage.asp">
-
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.
-
dim MyVar
-
MyVar = request.form("text1")
-
if MyVar = Pass then
-
'correct password
-
end if
-
To understand form submission for ASP and VB better you should go here.
http://www.w3schools.com/ASP/asp_inputforms.asp