Solved

VB and VBSCript

Posted on 2000-04-27
3
305 Views
Last Modified: 2010-05-18
I'm building a web page which allows the user to add information into database, and then displays the orignal page with a message -- error or confirmation. I also want to change the "Add" button to "Update" button.

I wrote VBScript to make sure that the user must enter data in some text fields.

Could you please help me to solve the problem I have:

If I choose input type as "Submit" ( <INPUT TYPE="Submit" VALUE="Add" Name="cmdSubmit">),the following code won't work:
 
<Script Language = "VBScript">

  Dim TheForm

  Sub Window_OnLoad
     Set TheForm = Document.FormAddAgency
  End Sub

  Function IsFieldEmpty(field, mes)
      If Len(field.value) = 0 Then
           Alert Mes
           field.focus
           IsFieldEmpty = False
      Else
           IsFieldEmpty = True
      End If
   End Function


 Sub cmdSubmit_OnClick
   Set ChkField = TheForm.FullName
       If Not IsFieldEmpty(ChkField, "Please enter Agency Name" ) Then
           Exit Sub
        End If

        Set ChkField = TheForm.ShortName
        If Not IsFieldEmpty(ChkField, "Please enter Agency Short Name") Then
            Exit Sub
        End If
        TheForm.submit

   End Sub

</Script>

If I choose input ytpe as "button" (<INPUT TYPE="button" VALUE="Add" Name="cmdSubmit">), the following won't work properly:

Select Case Request("cmdSubmit")
    Case "Update"
         Session("MessageType") = "Update"
         Session("Message") = "The current agency """ & Request.Form("FullName") & """ has been updated."
     Case "Add"
         Session("MessageType") = "Add"
         Session("Message") = "New agency """ & Request.Form("FullName") & """ has been added."
    End Select


0
Comment
Question by:leeann
  • 2
3 Comments
 
LVL 18

Accepted Solution

by:
mdougan earned 100 total points
ID: 2756401
Do you call different OnClick procedures for the Add and Updates?

If I were you, I'd have a hidden field in the same form as the button, then, in the OnClick procedure, set the value of the hidden field to Add or Update depending on which button you clicked.  Then, instead of checking the value of cmdSubmit, you'd check the value of the hidden form field instead.

If you don't have a separate OnClick procedure, then I think you can pass a parameter to the OnClick procedure, and that Parm could be different for the Add and Update buttons.  Sorry, I don't have sample code for this, but it's pretty basic.
0
 

Author Comment

by:leeann
ID: 2756452
Thanks! Mdougan,

The part of the "Select Case" code is VB code, and the OnClick procedure is VBScript code is running in client side.

Could you please tell me how to pass the flag "Add" or"Update through the OnClick procedure to VB code which is running on web server machine?

0
 
LVL 18

Expert Comment

by:mdougan
ID: 2757953
Well, you didn't show all of your client side code, but say that you have your procedure:

Sub cmdADD_OnClick

      myform.MODE.Value = "Add"
     
   Set ChkField = TheForm.FullName
       If Not IsFieldEmpty(ChkField, "Please enter Agency Name" ) Then
           Exit Sub
        End If

        Set ChkField = TheForm.ShortName
        If Not IsFieldEmpty(ChkField, "Please enter Agency Short Name") Then
            Exit Sub
        End If
        TheForm.submit

   End Sub

Sub cmdUpdate_OnClick

      myform.MODE.Value = "Update"
     
   Set ChkField = TheForm.FullName
       If Not IsFieldEmpty(ChkField, "Please enter Agency Name" ) Then
           Exit Sub
        End If

        Set ChkField = TheForm.ShortName
        If Not IsFieldEmpty(ChkField, "Please enter Agency Short Name") Then
            Exit Sub
        End If
        TheForm.submit

   End Sub

Then further down in the client code:

<form name='myform'>
<INPUT TYPE="HIDDEN" NAME="MODE"
<INPUT TYPE="button" VALUE="Add" Name="cmdADD">
<INPUT TYPE="button" VALUE="Update" Name="cmdUPdate">
</form>

In your server code:

Select Case Request("MODE")
    Case "Update"
         Session("MessageType") = "Update"
         Session("Message") = "The current agency """ & Request.Form("FullName") & """ has been updated."
     Case "Add"
         Session("MessageType") = "Add"
         Session("Message") = "New agency """ & Request.Form("FullName") & """ has been added."
    End Select
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question