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

Declaring & Initializing Variables 1

Status
Not open for further replies.

snaegs99

Programmer
Oct 10, 2001
12
US
Hi All,
I hope you can help me... I am very new to ASP and I am trying to declare a variable and initialize the variable to 0. The following is what I've tried in the body of my code:

<% Dim scID %>
<% scID = 0 %>
scID= <% =scID %>

when it displays on the screen scID has a null value. I've tried initializing it as a string, but it was still null. Any help would be greatly appreciated!
~Sarah
 
Hi Todd,
Quick question - I have this button as a column heading of a table and here's how I initialize it:

<TH ALIGN=center><INPUT TYPE=button name=cmdDelete value=&quot;Delete&quot; ONCLICK=cmdDelete_Click</TH>

I have a generic sub-routine set up so I can see if the ONCLICK command is working, and it isn't:

Sub cmdDelete_Click
MsgBox(&quot;Deleting an item from Shopping Cart&quot;)
End Sub

When the page is opened, it gives me a Syntax error on the button initializing line and will not execute the sub-routine, but everything works fine if I take out the &quot;ONCLICK=cmdDelete_Click&quot;.

The sub-routine is inside a VBSCRIPT tag along with other sub-routines that work fine. I have also used a Message Box and the ONCLICK command at other places and they've never given me this problem. Do you think it may be because it's in a table, and if so (or if not) how can I go about doing this?
 
Hmm.. I don't use VB Script on the client side, so I'm not absolutely sure. But I did spot a few items with room for improvement in that tag. So try this.

Code:
<TH ALIGN=center><INPUT TYPE=&quot;button&quot; name=&quot;cmdDelete&quot; value=&quot;Delete&quot; onClick=&quot;cmdDelete_Click&quot;></TH>

Now if that were JavaScript, the tag would actually look like this.

Code:
<TH ALIGN=center><INPUT TYPE=&quot;button&quot; name=&quot;cmdDelete&quot; value=&quot;Delete&quot; onClick=&quot;cmdDelete_Click();&quot;></TH>

And the Function would look like this. (Between the <head></head> tags in the HTML)

Code:
<script Language=&quot;JavaScript&quot;>
function cmdDelete_Click() {
  window.alert(&quot;Hey, it's working in JavaScript&quot;)
}
</script>

If you still get stumped, you might want to post a new thread in the ASP forum or the VB forum.

Hope this helps :)

ToddWW
 
If u declare a session variable in this way Session(&quot;myVar&quot;)=0 u dont need to convert it to an number cuz is already an number so u dont need CInt CStr conversion, but....
If u need to go with that use Int or Str instead of CInt or CStr cuz this functions causes me a lot of troubles...
Anyways hope this helps... ________
George, M
 
And for the last question
If u need to add an event handler on VBScript just declare the sub as u sayed without ONCLICK=cmdDelete_Click thing
:
Code:
TH ALIGN=center><INPUT TYPE=button name=cmdDelete value=&quot;Delete&quot;</TH>

Sub cmdDelete_Click
    MsgBox(&quot;Deleting an item from Shopping Cart&quot;)
End Sub

How to declare an event in VBScript:
1. U need the name of the html tag - ie. cmdDelete
2. U need the event name - ie. onclick
3. Create an sub with the name like this cmdDelete_onclick - ie. Sub cmdDelete_onclick

Hope this helps...
________
George, M
 
Sorry the lines
Sub cmdDelete_Click
MsgBox(&quot;Deleting an item from Shopping Cart&quot;)
End Sub
should be

Sub cmdDelete_OnClick
MsgBox(&quot;Deleting an item from Shopping Cart&quot;)
End Sub

________
George, M
 
OK, now that I got the function working and I looked in a couple forums and realized I can't do server-side database manipulations in this function, I'm stuck again.

In this function I need to delete records from the database on the server.

This is what I wrote so far:

<% Dim connCW %>
<% Set connCW = Server.CreateObject(&quot;ADODB.Connection&quot;) %>
<% connCW.Open &quot;Driver={Microsoft Access Driver (*.mdb)};DBQ=D:\home\snaegele\Cougar\Cougar.mdb&quot; %>

<SCRIPT LANGUAGE=&quot;VBSCRIPT&quot;>
Sub cmdDelete_OnClick
Dim i, strDate, message, rsDelete, strQuery, strID, intscid
For i=0 to Document.frmdisplaysc.Elements.Length - 1
If Document.frmdisplaysc.Elements(i).Name = &quot;del&quot; Then
If Document.frmdisplaysc.Elements(i).Checked Then
<% strID = Session(&quot;scID&quot;) %>
<% intscid = CInt(strID) %>
strQuery = &quot;DELETE FROM SHOPPINGCART WHERE SCID = &quot; & intscid & &quot; AND DATE = &quot; & Document.frmdisplaysc.Elements(i).VALUE
* connCW.Execute(strQuery)
Navigate (&quot;displaysc.asp&quot;)
Exit For
End if
End if
Next
End Sub

</SCRIPT>


I get the error message that says:
Error:Object required: 'connCW'
on the line with the *

The sub-routine is executed when they click the cmdDelete button and checks all of the check boxes(Name=&quot;del&quot;) in the table to see if they are checked or not - if they are, that item(recognized by the SCID and the DATE columns in the table) is deleted from the table and the page is refreshed showing the Shopping Cart without the deleted item.

Is there a way to write this function server-side instead of client-side, and if not, how can I do this on the client-side?
 
Well, you're right, you can't make database manipulations on the client side. You will need to do this on the server side. Shaddow has chimed into this thread and I would hate for both of us to be working on the same solution for you at the same time. Things can get confusing then. If you would like my help with this, let me know.

Otherwise, we should wait a few minutes, Shaddow may be coming up with something for you right now as we speak ..

ToddWW :)
 
If u are so good why dont help him with the last question, cua i dont have lots of time to spear like you... and maybe u will see that the line
Code:
<SCRIPT LANGUAGE=&quot;VBSCRIPT&quot;>
should use RUNAT=Server to work...or maybe not!?!?
i hope i was clear enought...
i just want to help... ________
George, M
 
I'm not so good, and you are helping. I don't mind working with other members to help one person. As a matter of fact, I encourage it. Most of my answers do work, but by no means are they the best solution. Two heads are always better than one. It's just that after Sarah's last question, I could see that she was going to need more than a few one line answers because she was confusing client side script with server side script.

Actually, I was initially confused when I saw that script tag also, but after looking at it more detail, it realized that it actually IS client side script that she is writing. I looked at other pages on her site and she is doing all of her client side script in VBScript. I warned her about NS compatibility, but it's a school project so she's going to stick with it. She writes CS VBScript a whole hell of alot better than I do.

At any rate, she was confusing the client side and the server side script. Thinking she could comingle the two in the purpose that when someone ran a client side function, it would go to the server and run the server side script as she wrote it in her previous example.

So to answer your question, that script is not intended to be run on the server. (Well at least most of it). All I had to do was teach her a simple post method to post the form data to the server for processing.

I certainly appreciate your help here and on any other threads that I reply to, or post for that matter. I apologize if I came off the wrong way before.

ToddWW :)
 
I apreciate your answer and your help on this forum, and i apologize to, i didnt know that u want to teach snaegs99 something and that u are aware of his problems...
Cheers George ________
George, M
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top