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

Code Run after field Update

Status
Not open for further replies.

mswilson16

Programmer
Nov 20, 2001
243
US
Hi All,

I am used to writing apps in access and Vb were you can use the AfterUpdate Function... I am now writing a ASP app (with SQL back end) and I need to be able to call a function once a field is updated/exited... how do I do this?

e.g.

when the field
<td> <input name="Entity_Name" type="text" size="32"> </td>
is exiting I want to call CheckIfClientExist

Thanks in advance

Mswilson
 
Either submit the form when the field is changed; or load the entire table of clients into a Javascript array when building the page containing the form and use Javascript to check. If there are only a few clients, the Javascript approach could work, but for a large number you will need to process the form and rebuild it possibly with an error message. Unless you are using .NET which may provide an alternative.

Code:
<%
...
If Request.Form("check_client") = "yes" Then
  'Look up in database
  'Build error message if not found
EndIf
...
'Build form again including client name.
%>
<html>
<form name="MyForm">
...
<td> <input name="Entity_Name" type="text"  size="32" onchange="checkIfClientExists()"> </td>
<input type="hidden" name="check_client" value="">
...
</form>
...
<script>
function checkIfClientExists(){
    document.MyForm.check_client.value = "yes";
    document.MyForm.submit();
}
</script>
</html>
 
I agree with rac2, this sounds like a client-side scripting question... not an ASP question.

Use JavaScript and the properties and events of the browser's "Document Object Model
 
ok, I just want to show a message box after the field is exited... I have tried the following


<td> <input name="Entity_Name" type="text" onChange="<% Call CheckIfClientExist %>" size="32"> </td>

Function CheckIfClientExist
msg = "Umm, I guess, EOF?"
Response.Write("<" & "script>alert('" & msg & "');")
Response.Write("<" & "/script>")
End Function

So I no have two problems/questions... 1) will this run when the field is exited, or when every key is pressed? 2) nothing is happening with the above... anybody know why?
 
Your ASP code is processed on the server before the page is served. Use a clientside solution (as suggested above)

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
It might help to think of the timeline:

1. Browser sends request to IIS web server.

2. IIS passes request to ASP.

3. ASP creates a response using HTML, JavaScript, CSS, and so on... hands back to IIS

4. IIS sends response to Browser.

5. Browser parses response into Document Object Model, runs scripts, renders page, and other stuff like sending additonal requests to web server in response to <img> tags.

6. User views page, may take actions that raise DOM events in browser.


So you're trying to accomplish something in step 3 that should be handled in step 6...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top