Smart questions
Smart answers
Smart people
Join Tek-Tips Forums
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

GoTerps88 (Programmer) (OP)
7 Jun 07 20:01
I want to be able to loop through form elements of type checkbox on form.  How would I accomplish this in VBScript?

A sample would be great.  I wasn't able to located on online.

Thanks...
monksnake (Programmer)
8 Jun 07 9:43
How does this relate to ASP?  In order to loop through the form elements, the form elements have to exist first.  The elements won't exist until after all the server side code executes.




monkeysnake <.

GoTerps88 (Programmer) (OP)
8 Jun 07 9:57
This function would run on a button click after the page has been loaded, so the form elements would exist.  I've done this in Javascript.
tsuji (TechnicalUser)
8 Jun 07 10:58
Take it to vbscript forum and I'll help you.
    http://tek-tips.com/threadminder.cfm?pid=329
Sheco (Programmer)
8 Jun 07 11:04
It seems like you want to do something with client-side script.  

Although it is possible to write client-side script using VBScript, it is not advisable.  You're usually better off doing the client-side work in JavaScript.  I prefer to write server-side logic in VBScript and client-side logic in JavaScript so I never have to wonder if I'm looking at server or client code.
monksnake (Programmer)
8 Jun 07 11:12
I write it all in javascript cause I'm cool like that pimp

monkeysnake <.

Turkbear (TechnicalUser)
8 Jun 07 11:29
Hi,
In this VBScript snippet I loop through all the controls on a page and, if they are of a particular type and are in a visible panel,take some action( Ignore the actions taken just look at the code that does the scanning for controls..)

CODE

 Dim Fctl,Ptl as Control
          Dim ValStr,NamStr As String
          Dim ix As Integer
          For each Fctl in form1.Controls
           If  Fctl.GetType() Is GetType(Panel) Then
          
               If Ctype(Fctl,Panel).Visible = True  Then
                   
                   For Each Ptl in Ctype(Fctl,Panel).Controls
                   
                If Ptl.GetType() Is GetType(ListBox) Then
                    
                    NamStr = NamStr & CType(Ptl, ListBox).ID & ","
                     For ix = 0 To     CType(Ptl, ListBox).Items.Count - 1
                     
                      If CType(Ptl, ListBox).Items(ix).Selected Then             
                         ValStr = ValStr & CType(Ptl, ListBox).Items(ix).Value & ","
                        VPrmpt = VPrmpt & CType(Ptl, ListBox).Items(ix).Value & ","
                    End If
                    
                  Next  ' ix                
                   If Session("Viewer") =  "Actx" Then                    
                     VPrmpt = Left(VPrmpt,Len(VPrmpt) - 1)
                     Prmpts = CwrPrefix & CType(Ptl, ListBox).ID & "=" & VPrmpt
                     FullStr = FullStr & Prmpts
                   End If
                   VPrmpt=""            
                   ValStr = Left(ValStr,Len(ValStr) - 1) & ";"                      
             
              'End If   ' Finished with testing Type of Control in Panel
              ElseIf Ptl.GetType() Is GetType(TextBox) Then     
                       NamStr = NamStr & CType(Ptl, TextBox).ID & ","     
                      ValStr = ValStr & CType(Ptl, TextBox).Text & ";"
                      VPrmpt = VPrmpt & CType(Ptl, TextBox).Text & ";"
                    If Session("Viewer") =  "Actx" Then                    
                    VPrmpt = Left(VPrmpt,Len(VPrmpt) - 1)
                    Prmpts = CwrPrefix & CType(Ptl, TextBox).ID & "=" & VPrmpt
                    FullStr = FullStr & Prmpts
                 End If
                 VPrmpt=""
           End If
         Next   ' Ptl inPanel Control
      End If
     End If
    Next

profile

To Paraphrase:"The Help you get is proportional to the Help you give.."

Sheco (Programmer)
8 Jun 07 11:37
Ah yes but it is client-side logic, not ASP logic.  

What I mean is, although it could be included in a file with a .ASP extension, it is not actually executed on the server by the ASP engine... it could run just as well in an .HTM file because the logic is run by the IE browser.
Turkbear (TechnicalUser)
8 Jun 07 12:05
Hi,
This is .NET 2.0 by the way ( sorry for not specifying) and all the actions are set to run at Server..Maybe it is a definitional thing but I have always thought that that meant server-side actions, not client.
snippet:

CODE

<form id="form1" runat="server">
 <td>
          <button id="Button1"
              OnServerClick="ShowChoice"
              runat="server">

   Run Report

    </button></td>
</form>

profile

To Paraphrase:"The Help you get is proportional to the Help you give.."

Sheco (Programmer)
8 Jun 07 12:27
Ah, ASP.NET is a totally different creature... it has its own forum: forum855: Microsoft: ASP.NET

Basically the way runat="server" works in ASP.NET is it tells the server script to make an object in memory that resembles the HTML tag you stick it in.  So for example if you put it in an HTML tag for a textbox it will create an object with a Value property and if you put it on an IMG tag it will create an object with a SRC property.  Then you can manipulate the value in code and the ASP.NET will send the final resulting HTML to the browser.

So in classic ASP you might do this:

CODE --> ASP

<% If x > 10 Then %>
      <img src="big.gif">
<% else %>
      <img src="small.gif">
<% end if %>


But in ASP.NET you could do this:

CODE --> ASPX

<script runat="server">
    If x > 10 Then
      foo.Src = "big.gif"
    Else
      foo.Src = "small.gif"
    End If        
</script>

<img id="foo" runat="server" />


Both the ASP and ASPX will produce an HTML image tag with the proper value of SRC so the browser will display them the same.  The advantage to the ASPX version is it helps keep the logic a bit more separated from the HTML.
GoTerps88 (Programmer) (OP)
8 Jun 07 13:22
Tsuji, I submitted it there.

Thanks

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close