I’m having a problem getting javascript and vbscript to place nicely together. Here is what I want to do:
I’m getting values from my database for different exam types. Here are some sample values:
Exam Type1
Exam Type2
Exam Type3
Here is how I get the values in vbscript:
<% 'Query to print out available exam types for the user to see
set my_rs = server.createObject("ADODB.recordset")
my_rs.open my_sql, my_conn
dim existingExamCat
existingExamCat = ""
if not(my_rs.bof and my_rs.eof) then
do while not (my_rs.eof)
response.write my_rs.fields("examTypeCat") & "<br>"
existingExamCat = existingExamCat & my_rs.fields("examTypeCat") & ","
my_rs.movenext
loop
my_rs.close
else
response.write "There are no available exam types at this time."
end if
response.write "<br><br>" & existingExamCat
set my_conn = nothing
set my_rs = nothing
%>
The above vbscript works fine and gives me the correct results.
I set up another variable called existingExamCat to keep track of all the exam categories in a comma-delimited list. This is at the bottom of my page.
<script language=“javascript”>
var existingExamCat = "<%= existingExamCat %>";
</script>
Then at the top as part of an onClick event, I have this:
function validateUniqueType ()
{
var newType = document.formAddExamType.exam_newType.value;
var compareString;
'alert (newType);
}
I want to see if the variable “newType”, which is entered by the user in a text input box exists in the list of already populated exam names.
So existingExamCat = “Exam Type1,Exam Type2,Exam Type3,”
and the variable “newType” is working. I want to compare newType & existingExamCat. I’ve looked all around online and am getting frustrated. Any help would be appreciated. Thanks!