Javascript Validations
Hi people,
I have writtem some code so that after a person has clicked on 2 selections in 2 different select lists, the submit button appears at teh bottom of the form,I am attempting to now make the submit button only appear after a further text areas on teh form has been filled in and I can't do it. here is the code
html>
<head>
<TITLE>Category and Subcategory Drop Down Lists Demonstration</TITLE>
<title>Inputting a new Question</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<SCRIPT Language="JavaScript">
function lawChanged()
{
if(form1.LawSelect.selectedIndex==0){ alert("You must choose a Law")}
else
{
form1.action="http://pertinax.cms.shu.ac.uk/mmtec/mm32/HughInputAQuestion1b.asp"
form1.submit()
}
}
function mySubmit()
{
somethingWrong=false
if(form1.ComponentSelect.selectedIndex==0)
{
alert("You must choose a Component")
somethingWrong=true
}
if(form1.LawSelect.selectedIndex==0)
{
alert("You must choose a Law")
somethingWrong=true
}
if(form1.questionText.value="")
{
alert("You must choose a Component")
somethingWrong=true
}
if (!somethingWrong)
{
alert("LawNo selected =" + form1.LawSelect.selectedIndex + " and component selected is " + form1.ComponentSelect.selectedIndex)
astring="http://pertinax.cms.shu.ac.uk/mmtec/mm32/HughInputAQuestion2.asp?LawNo=" + form1.LawSelect.selectedIndex+"&ComponentNo=" + form1.ComponentSelect.selectedIndex
alert("Am calling " + astring)
form1.action= astring
document.all.Submit.style.visibility='visible'
}
}
function ComponentChanged()
{
if(form1.ComponentSelect.selectedIndex==0)
{ alert("You must choose a Component")
}
}
</SCRIPT>
</head>
<body>
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
HaveChosen=False
Set MyConn=Server.CreateObject("ADODB.Connection")
Set Rs=Server.CreateObject("ADODB.RecordSet")
Set Rs2=Server.CreateObject("ADODB.RecordSet")
MyConn.Open("mm32")
Rs.Open "SELECT * From Law ORDER by lawNo", MyConn, 1, 2
LawChosen=Request.Form("LawSelect")
If Not IsNull(LawChosen) Then
LawChosen=Cint(LawChosen)
SQLString="SELECT * From Component WHERE lawNo=" & LawChosen
Rs2.Open SQLString, MyConn, 1, 2
HaveChosen=True
End If
Response.write("")
Response.write("<P>")
Response.write("<P>")
Response.write("First Select a Law<P>")
Response.write("<form name='form1' method='post' >")
Response.write("<SELECT Name='LawSelect' SINGLE size=10 onChange='lawChanged()'> ")
Response.write("<OPTION Value='NONE'>--Choose a Law--")
While NOT Rs.EOF
astring="<OPTION VALUE=" & Rs("lawNo")
If Rs("lawNo") = LawChosen Then
astring=astring & " SELECTED"
End if
Response.write(astring & ">" & Rs("lawNo") & ". " & Rs("lawText"))
Rs.MoveNext
WEND
Response.write("</SELECT>")
If HaveChosen Then
Response.write("<SELECT Name='ComponentSelect' SINGLE size=10 onChange='ComponentChanged()' > ")
Response.write("<OPTION Value='NONE'>--Choose a Component--")
While NOT Rs2.EOF
astring="<OPTION VALUE=" & Rs2("componentNo") & ">" & Rs2("componentNo") & ". " & Mid(Rs2("componentText"),1,30)
Response.write( astring & "<BR>")
Rs2.MoveNext
WEND
Response.write("</SELECT>")
End If
%>
All our questions are going to be multiple choice so please tap your question in here.Please dont make it a question that yields a yes/no answer<br>
<textarea cols = 100 rows =2 name=questionText wrap=hard></textarea><br>
<%
Response.write("<p>")
Response.write(" <input type='submit' name='Submit' value='Submit' onClick='mySubmit()' STYLE='visibility:hidden'>")
Response.write("</p>")
Response.write("</form>")
Response.write("<p><strong></strong> </p>")
%>
</body>
</html>
I would be so grateful if you could help
andrew
|