Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Please help, VBScript in HTML question!

Status
Not open for further replies.

Zoplax

Technical User
Oct 2, 2002
58
US
Hello, with the following VBScript in an HTML doc I keep getting a "type mismatch" error when I click the Submit button; it tries but fails to call the function.

Please help! The code is below, it can be pasted into an HTML doc.

---

<HTML>

<HEAD>

<SCRIPT language="VBScript">
<!--
SUB btnLogin_onClick

login()

end sub

function login()

dim strUserName, strPassword, strDepartment

strUserName = document.frmLogin.txtUserName.value
strPassword = document.frmLogin.txtPassword.value
strDepartment = document.frmLogin.lstDepartment.value

select case strUserName
case "KFoster"
if (strPassword = "MST3K") then window.location.href = strDepartment & ".htm"
end if
case "CSchwab"
if (strPassword = "OKC802") then window.location.href = strDepartment & ".htm"
end if
case "FHelms"
if (strPassword = "Telcom52") then window.location.href = strDepartment & ".htm"
end if
case "KShea"
if (strPassword = "Ghost716") then window.location.href = strDepartment & ".htm"
end if
case else window.location.href="loginFormVB.htm"

end select

end function


-->
</SCRIPT>
</HEAD>

<TITLE>Login Form</TITLE>

<BODY>

<CENTER>

<h1>Login Form</h1>

</CENTER>

<FORM method="post" name="frmLogin" action="javascript:void(0)">

<INPUT type="text" name="txtUserName">UserName<BR><BR>

<INPUT type="text" name="txtPassword">Password<BR><BR>

<P>
Department
<SELECT name="lstDepartment" size="1">
<OPTION value="administration">Administration</OPTION>
<OPTION value="customer">Customer</OPTION>
</SELECT>
</P>

<P><INPUT type="button" value="Go to the Department Website!" name="btnLogin"></P>

<P><INPUT type=button name="btnClear" value="Clear Form"; ></P>


<SCRIPT FOR="btnLogin" EVENT="onClick" LANGUAGE="VBScript">

login

</SCRIPT>
</FORM>
</BODY>
</HTML>



 
I don't think you need this at all:
Code:
<SCRIPT FOR="btnLogin" EVENT="onClick" LANGUAGE="VBScript">

      login

</SCRIPT>

[blue]"Well, once again my friend, we find that science is a two headed beast. One head is nice, it gives us aspirin and other modern conveniences,...but the other head of science is BAD! Oh, beware the other head of science, Arthur; it bites!!" - The Tick[/blue]
 
Here is the code minus the other script for the button's onClick event.

Still produces the same error, "type mismatch: login".

Any other ideas?? :(


---


<HTML>

<HEAD>

<SCRIPT language="VBScript">

OPTION EXPLICIT

function login()

dim strUserName, strPassword, strDepartment

strUserName = document.frmLogin.txtUserName.value
strPassword = document.frmLogin.txtPassword.value
strDepartment = document.frmLogin.lstDepartment.value

document.frmLogin.lstDepartment.focus()
document.frmLogin.lstDepartment.select()

select case strUserName

case "KFoster"
if (strPassword = "MST3K") then window.location.href = strDepartment & ".htm"
end if
case "CSchwab"
if (strPassword = "OKC802") then window.location.href = strDepartment & ".htm"
end if
case "FHelms"
if (strPassword = "Telcom52") then window.location.href = strDepartment & ".htm"
end if
case "KShea"
if (strPassword = "Ghost716") then window.location.href = strDepartment & ".htm"
end if
case else window.location.href="loginFormVB.htm"

end select

END FUNCTION

</SCRIPT>

</HEAD>



<TITLE>Login Form</TITLE>

<BODY>

<CENTER>

<h1>Login Form</h1>

</CENTER>

<FORM method="post" name="frmLogin" action="javascript:void(0)">

<INPUT type="text" name="txtUserName">UserName<BR><BR>

<INPUT type="text" name="txtPassword">Password<BR><BR>

<P>
Department
<SELECT name="lstDepartment" size="1">
<OPTION value="administration">Administration</OPTION>
<OPTION value="customer">Customer</OPTION>
</SELECT>
</P>

<P><INPUT type="button" value="Go to the Department Website!" name="btnLogin" onClick="login()"></P>

<P><INPUT type=button name="btnClear" value="Clear Form"; ></P>


</FORM>
</BODY>
</HTML>
 
action="javascript:void(0)"
onClick="login()"
IE maybe thinks login() is a javascript function.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Argh.. I removed the javascript:void(0) statement but still the same thing, Type mismatch: 'login'

The line number referenced by the error in IE is the line where the button is defined if that helps...
 
What a PAIN, I found the problem.

IE didn't like the End Ifs within the Select Case appearing on a different line; I moved it so that it looks like:

if (strPassword = "MST3K") then window.location.href = strDepartment & ".htm" end if

Now suddenly the form starts working. Man... :p
 
Have you tried this ?
onClick="login"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Now your "End If" brackets are being ignored, so it'll work.

It would be more correct to omit them.

There are two forms of If statement, a block If and a single-line If. Only block Ifs use End If.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top