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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sending an alert during server side validation

Status
Not open for further replies.

blexman

Programmer
Jul 18, 2001
34
0
0
CA
I am checking if a number exists in the database on the server side using ASP. If that number is not found I would like to send a messge to the screen via an alert (or document.write). then I would like the original screen back with the invalid field highlighted..I tried this but when the alert pops up the screen is white...the form is gone until i clear the alert.
...
....
If objRS.EOF Then
objRS.Close
Set objRS = Nothing
Set objCommand = Nothing
<script language=&quot;JavaScript&quot; type=&quot;text/javascript&quot;>
<!--
var strTran = &quot;<%=varTran%>&quot;;
alert(strTran)
document.frm.Tran.focus()
//-->
</script>

thanks
hanton
 
Stick your <script> tags below all your pagecode.

.
.
.
page here
.
.
</body>
<script>
...
</script>
</html>
 
do not quite get what you mean but I changed my code as follows and it did not work :

<HTML>
<HEAD></head>
<body>

...
....
If objRS.EOF Then
objRS.Close
Set objRS = Nothing
Set objCommand = Nothing
DO I NEED TO CALL THE JAVASCRIPT FUNCTION FROM HERE ???
end if
...
...
</body>
<script language=&quot;JavaScript&quot; type=&quot;text/javascript&quot;>
<!--
function alertInvalidTransit() {
var strAgency = &quot;<%=varMergedWithTransit%>&quot;;
alert(strAgency)
document.frmTransitInformation.MergedWithTransit.focus()
}
//-->
</script>
</html>

thanks
hanton
 
..sorry ignore my previous post until I fix the typos!!
 
Ok typos fixed.....

do not quite get what you mean but I changed my code as follows and it did not work :

<HTML>
<HEAD></head>
<body>

...
....
If objRS.EOF Then
objRS.Close
Set objRS = Nothing
Set objCommand = Nothing
DO I NEED TO CALL THE JAVASCRIPT FUNCTION FROM HERE ???
end if
...
...
</body>
<script language=&quot;JavaScript&quot; type=&quot;text/javascript&quot;>
<!--
function alertInvalidTran() {
var strTran = &quot;<%=varTran%>&quot;;
alert(strTran)
document.frm.Tran.focus()
}
//-->
</script>
</html>

thanks
hanton
 
well, if you need to use your objRS in your code, but don't want to call the javascript until the whole page is loaded, do something like this:

<HTML>
<HEAD></head>
<body>

...
....
<%
If objRS.EOF Then
objRS.Close
Set objRS = Nothing
Set objCommand = Nothing
boolBadInput = true
end if
%.
...
...
</body>
<% if boolBadInput then %>
<script language=&quot;JavaScript&quot; type=&quot;text/javascript&quot;>
<!--

var strTran = &quot;<%=varTran%>&quot;;
alert(strTran)
document.frm.Tran.focus()
//-->
</script>
<% end if %>
</html>


This will print out the javascript code at the end of your code if the rsObj is EOF. The javascript will execute after your page is loaded because it is printed at the end.

Note that the javascript isn't in a function, its just straight lines of code. So you don't need to call it, it will get executed as its parsed by the browser.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top