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

Client side validation with DTCs and SOM

Status
Not open for further replies.

mnongkhlaw

Programmer
Feb 22, 2002
62
0
0
IN
Dear folks,

This problem's been bugging me for quite a while! I have to repost differently, I guess as I did not get any help so far.

I've got an ASP which uses the FormManager DTC along with 2 textboxes, txtVendorID & txtVendorName bound to an Access table with fields VendorID and VendorName respectively. VendorID is defined as a primary number field, whereas VendorName is a text field. The FormManager DTC manages the form mode and events for the buttons Add,Update,Delete,Save and Cancel.

I'd like a client-side validation routine so that when the user tries to add a new record by clicking Save button, it should check that (i) the value entered for the VendorID should not be a duplicate one and (ii) VendorName should not be blank.

I have no idea for (i) but for (ii), I tried the following code in the <HEAD> portion of the page, but it does not work at all :-

<SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript>
<!--
function thisPage_onbeforeserverevent(obj,event)
{
if (obj==&quot;cmdSave&quot;)
{
if(event==&quot;onclick&quot;)
{
if(document.thisForm.txtVendorName.value==&quot;&quot;)
{
alert(&quot;Vendor name cannot be blank!&quot;);
thisPage.cancelEvent = true;

document.thisForm.txtVendorName.focus();

}}}}
// -->
</SCRIPT>

What is wrong with this code and how can I also implement (i) above?

Your help will be greatly appreciated.
 
I don't do Javascript, but since you say you have not gotten an answer yet, I'll say this. You might get more information in the in the Javascript forum. I do dabble in Javascript a little, but I can't see anything wrong with your code. In VBScript I would use this to do (ii)

Code:
<%ScriptLanguage = VBScript%>
If txtVendorName.text = &quot;&quot; Then
  MsgBox(&quot;Vendor Name can not be blank!&quot;)
End If

For (i) using VBScript you will have to submit the information in the TextBox via another asp page, to a query to see if the information is already in the database, and redirect to the original page after the query has run.

Hope this is of some help.

Rob
Just my $.02.
 
Your code looks correct, so there must be some other reason for failure.

Did you add a PageObjectDTC to the page? This creates the thisPage object against which the event runs.

Secondly, try some alerts to see what values are sent to the event.

In Interdev, try getting the Script Outline view to show up (it may be a tab in the Toolbox area).

Under the Client Objects and Events twig, you should see the thisPage. Note: thisPage is an alias for the name of the PageObjectDTC - usually the same as the page itself, unless there are two pages with the same name, in different subdirectories - and then the DTC should have a unique name (so that any Session values are stored with different names too).
Under the thisPage twig, you should see the onbeforeserverevent. If it is in bold then you have added your code correctly. Double-click this event name, and you will be taken to either the existing code, or to a newly created function. This guarantees that the Javascript block is well formed, but...

If a new Javascript block is created, containing this onbeforeserver... function, you will notice that it does not have any parameters. Add these your self! (as you have done in your code).

As for problem i. There are several things you could try:

1. (for small-ish lists) Create a list of existing values and send then to the web page as either a hidden field or (better still) as a javascript array. Your ASP code will need to create code!
With a hidden field, the values could be comma separated, so you would do a in-string type search.

2. You could try using the Execute facility of the PageObjectDTC. Create a SERVER SIDE function that takes the test value as a parameter, and contains code to test the database for duplicate. The function can return a string or number. Register this function in the DTC under the Execute pannel.
In the CLIENT SIDE script, you can call this function! In your onbeforeserverevent function, type:
if (thisPage.execute.<yourfunction>(<parameter>) == 1)
{
alert (&quot;This value already exists&quot;);
thisPage.cancelEvent = true;
}
The page will load up a JAVA APPLET that sends your function call to the server, and handles the reply value.
IF you are not allowed to use Java applets, then there are other ways...

3. Similar to 2. You can call a server-side function without a full page refresh. XML WebServices do just this, but for your purposes you could just try using the XMLDom that is included with later versions of Internet Explorer. You can load the XMLDom object in client-side script, Wrap up your parameters in some XML via the XMLDom, use the XMLDom Send method to send this XML to a URL. That URL (an ASP page) will load the XMLDom, fill it with the Request and yank out the values within it. It will then perform whatever actions you want (like the Duplicate Key check), and format an XML document to return to your web page.
Yes, it is a bit tricky, but it does work! You will need to do some reading and some hair pulling to get this going though.

Hope something here helps!

 
Thanks, MerlinB. I got the code for (ii) to work. I've yet to try your suggestions for (i). Will update.

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top