Forums
This topic is locked
Validating Form data against a database record
19 Feb 2004 03:15:59 Touti P posted:
Hi there,I am trying to validate the user's input by checking to see whether it exists in the database. Once the user enters the data, a vbscript function will be called on OnBlur. I don't want to submit the form just validate the input. This is what I have so far:
<script language="vbscript" runat="server">
sub RunQuery(tablename, fieldname)
Dim SQLStr, rs, db_conn
Set db_conn = Server.CreateObject("ADODB.Connection"
db_conn.Open DB_String
Set rs = Server.CreateObject("ADODB.Recordset"
SQLStr = "SELECT * FROM “ & tablename & “ WHERE “ & fieldname & “=” & document.getElementById(fieldname).value & ";"
rs.Open SQLStr, db_conn, 0, 1
If rs.EOF Then
msgbox("Symptom code does not exist!"
Else
msgbox("Code Exists!"
End If
end sub
</script>
Symptom Code: <input type="text" name="SymptomCode" id="SymptomCode" onblur="RunQuery(‘tblSymptomCode’, ‘SymptomCode’">
<input type="button" name="Submit" value="Submit">
Thanks!
Replies
Replied 19 Feb 2004 21:09:37
19 Feb 2004 21:09:37 Matthijs Horsman replied:
i don't think this is gonna work, because you have to submit something to the server, in order to run the query on your database.
Maybe you can use an <IFRAME> to run the query, just place a little iframe besides your input field and onBlur, run your query in your iframe. This way not the whole page will have to reload, but you can do a submit to teh server..
good luck
Matthijs
----------------
DWMX/W-XP-PRO/IIS/ASP-VB/MS-SQL
Maybe you can use an <IFRAME> to run the query, just place a little iframe besides your input field and onBlur, run your query in your iframe. This way not the whole page will have to reload, but you can do a submit to teh server..
good luck
Matthijs
----------------
DWMX/W-XP-PRO/IIS/ASP-VB/MS-SQL