Solved

VB and VBSCript

Posted on 2000-04-27
3
302 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now