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

Call a VBScript function with a button? 1

Status
Not open for further replies.

Beracosta

Programmer
Oct 25, 2000
47
0
0
SE
How do i make a VBScript function to activate when i press a button. The button is written in a asp file and the function that will be called should empty the shopping basket. Can anybody help me with this? (I think that James can ;)
 
If you are doing this client side you need to declare a function called
Code:
buttonname_Click
, and when the button is pressed then this code is invoked.
However, if you want to run this on the server-side, then use the POST method in your form and then use the button name to determine which one was pressed. you can then write the code to carry this out in the ASP page that is called.

James :)

ps am i getting well known or something? James Culshaw
jculshaw@active-data-solutions.co.uk
 
Hi thanx for your answer James. I'll now put the code here so u can help me even further =) So, when i click on the button Tabort, the table KorgInnehåll should be ereased for that KorgID that is present. Pls help me with this

<%

Dim oRs
Dim strSQL
Dim VaraPris, TotPris, Rabatt, Frakt
VaraPris = 0
TotPris = 0
Set oRs = Server.CreateObject(&quot;ADODB.Recordset&quot;)
With oRs
.ActiveConnection = &quot;DSN=SYCENT;&quot;
'DB Hintar
.CursorLocation = 3
.CursorType = 3
.LockType = 4
strSQL = &quot;SELECT Namn, Antal, Pris FROM KorgInnehall &quot; & _
&quot;INNER JOIN Varor ON KorgInnehall.VaruID = Varor.Id &quot; & _
&quot;WHERE KorgInnehall.KorgId = 5&quot;
.Open strSQL
Set .ActiveConnection = Nothing

if oRs.Recordcount = 0 then
Response.Write &quot;<font size=&quot;&quot;4&quot;&quot;>Din kundkorg är <font color=&quot;&quot;#D61303&quot;&quot;>tom!</font></font>&quot;
else
Response.Write &quot;<form name=&quot;&quot;KundKorg&quot;&quot;>&quot;
Response.Write &quot;<select name=&quot;&quot;Korgen&quot;&quot;>&quot;
While Not oRs.EOF
Response.Write &quot;<option SELECTED=&quot;&quot;true&quot;&quot; value=&quot;&quot;&quot; & oRs(&quot;Antal&quot;).Value & &quot; st &quot; & oRs(&quot;Namn&quot;).Value & &quot; á &quot; & oRs(&quot;Pris&quot;).Value & &quot; kr&quot; & &quot;&quot;&quot;>&quot; & oRs(&quot;Antal&quot;) & &quot; st &quot; & oRs(&quot;Namn&quot;) & &quot; á &quot; & oRs(&quot;Pris&quot;) & &quot; kr </option>&quot;
VaraPris = oRs(&quot;Antal&quot;) * oRs (&quot;Pris&quot;)
TotPris = Totpris + VaraPris
oRs.MoveNext
Wend
Response.Write &quot;</select> &quot;
Response.Write &quot; <input type=&quot;&quot;button&quot;&quot; name=&quot;&quot;Tabort&quot;&quot; value=&quot;&quot;Tabort varan&quot;&quot;>&quot;
Response.Write &quot;</form>&quot;
Response.Write &quot;Att betala: &quot; & TotPris & &quot; kr&quot;
end if


.Close

End With
Set oRs = Nothing

%>

PS.
And yes, u are getting well knowed, atleast by me =)
 
Can u please write the code for this? thanx in advance
 
Thanx James!!!!!!! U are my guardian angel. ;) hehe How come your so good at this? I wanna be just like u =) thanx alot!

PS.
The best thing about this is that i learn alot by trying all your things =) thanx again ;)
DS.

Björn
 
Try the follwoing, its not perfect as I hava a problem in not understanding your native language, but I am sure you'll get the idea.

Code:
<%

    Dim oRs, oCm
    Dim strSQL
    Dim VaraPris, TotPris, Rabatt, Frakt
    Dim intCounter
	VaraPris = 0
    TotPris = 0
    
	if Request.Form(&quot;Tabort&quot;) = &quot;&quot; then
	
		Set oRs = Server.CreateObject(&quot;ADODB.Recordset&quot;)
    	With oRs 
        	.ActiveConnection = &quot;DSN=SYCENT;&quot;
        	'DB Hintar
        	.CursorLocation = 3
        	.CursorType = 3
        	.LockType = 4
        	strSQL = &quot;SELECT Namn, Antal, Pris FROM KorgInnehall &quot; &  _
            	&quot;INNER JOIN Varor ON KorgInnehall.VaruID = Varor.Id &quot; & _
            	&quot;WHERE KorgInnehall.KorgId = 5&quot;
        	.Open strSQL
        	Set .ActiveConnection = Nothing
        
        	if oRs.Recordcount = 0 then
            	Response.Write &quot;<font size=&quot;&quot;4&quot;&quot;>Din kundkorg är <font color=&quot;&quot;#D61303&quot;&quot;>tom!</font></font>&quot;
        	else
        		Response.Write &quot;<form name=&quot;&quot;KundKorg&quot;&quot;>&quot;
        		Response.Write &quot;<select name=&quot;&quot;Korgen&quot;&quot;>&quot;
        		While Not oRs.EOF
            		Response.Write &quot;<option SELECTED=&quot;&quot;true&quot;&quot; value=&quot;&quot;&quot; & oRs(&quot;Antal&quot;).Value & &quot; st &quot; & oRs(&quot;Namn&quot;).Value & &quot; á &quot; & oRs(&quot;Pris&quot;).Value & &quot; kr&quot; & &quot;&quot;&quot;>&quot; & oRs(&quot;Antal&quot;) & &quot; st &quot; & oRs(&quot;Namn&quot;) & &quot; á &quot; & oRs(&quot;Pris&quot;) & &quot; kr </option>&quot;
            		VaraPris = oRs(&quot;Antal&quot;) * oRs (&quot;Pris&quot;)
            		TotPris = Totpris + VaraPris
            		oRs.MoveNext
        		Wend
        		Response.Write &quot;</select> &quot;
        		Response.Write &quot; <input type=&quot;&quot;button&quot;&quot; name=&quot;&quot;Tabort&quot;&quot; value=&quot;&quot;Tabort varan&quot;&quot;>&quot;
        		Response.Write &quot;</form>&quot;
        		Response.Write &quot;Att betala: &quot; & TotPris & &quot; kr&quot;
        	end if


    	.Close

    	End With
    	Set oRs = Nothing

	else
	
	  	for intCounter = 1 to Request.Form.Count
			if (Request.Form.Key(intCounter) <> &quot;Tabort&quot;) then
				intID = cint(Request.Form.Item(intCounter))
				strSQL = &quot;DELETE FROM MyTable WHERE id = &quot; & intID
				Set oCm = Server.CreateObject(&quot;ADODB.Command&quot;)
				With oCm
					.ActiveConnection = &quot;DSN=SYCENT;&quot;
				    .CommandType = adText
					.CommandText = strSQL
					.Execute
				End With
			end if
		next
 
 		Set oCm = Nothing
		
    end if
		
%>
James Culshaw
jculshaw@active-data-solutions.co.uk
 
Thanx for the help James, but it didn't work. It didn't happen anything when i pressed the button. I'll now put the same code again, but this time in English and hope that u can help me then =)

<%

Dim oRs
Dim strSQL
Dim MerchantPrice, TotPrice
MerchantPrice = 0
TotPrice = 0
Set oRs = Server.CreateObject(&quot;ADODB.Recordset&quot;)
With oRs
.ActiveConnection = &quot;DSN=SYCENT;&quot;
.CursorLocation = 3
.CursorType = 3
.LockType = 4
strSQL = &quot;SELECT Name, Quantity, Price FROM BasketContent &quot; & _
&quot;INNER JOIN Merchants ON BasketContent.MerchantID = Merchants.ID &quot; & _
&quot;WHERE BasketContent.BasketID = 5&quot;
.Open strSQL
Set .ActiveConnection = Nothing

if oRs.Recordcount = 0 then
Response.Write &quot;<font size=&quot;&quot;4&quot;&quot;>Din kundkorg är <font color=&quot;&quot;#D61303&quot;&quot;>tom!</font></font>&quot;
else
Response.Write &quot;<form name=&quot;&quot;Basket&quot;&quot;>&quot;
Response.Write &quot;<select name=&quot;&quot;Merchants&quot;&quot;>&quot;
While Not oRs.EOF
Response.Write &quot;<option SELECTED=&quot;&quot;true&quot;&quot; value=&quot;&quot;&quot; & oRs(&quot;Quantity&quot;).Value & &quot; st &quot; & oRs(&quot;Name&quot;).Value & &quot; for &quot; & oRs(&quot;Price&quot;).Value & &quot; $ each&quot; & &quot;&quot;&quot;>&quot; & oRs(&quot;Quantity&quot;) & &quot; st &quot; & oRs(&quot;Name&quot;) & &quot; for &quot; & oRs(&quot;Price&quot;) & each &quot; $ </option>&quot;
MerchantPrice = oRs(&quot;Quantity&quot;) * oRs (&quot;Price&quot;)
TotPrice = Totprice + MerchantPrice
oRs.MoveNext
Wend
Response.Write &quot;</select> &quot;
Response.Write &quot; <input type=&quot;&quot;button&quot;&quot; name=&quot;&quot;Empty&quot;&quot; value=&quot;&quot;Empty Basket&quot;&quot;>&quot;
Response.Write &quot;</form>&quot;
Response.Write &quot;To pay: &quot; & TotPrice & &quot; $&quot;
end if


.Close

End With
Set oRs = Nothing

%>

i hope u can help me better now, when u can understand the code =) thanx in advance and for all the help u are givving me ! :Þ
 
Multi select? Is that when u can select 2 or more merchants at the same time? If that is the case, no i don't.

Björn
 
And the code? =) Pls help me to rewrite my code that i posted a couple post above. pls......

Björn

bwt, did u see that i translated all the variables and texts to english =)
 
Have it post to a redirect page with the values '0' for the variable your emptying, then use response.redirect(&quot;whatever.asp?var=0&var2=0&quot;) or response.redirect(&quot;whatever.asp&quot;) and it should load it without anything in the basket...

OR...

above your code put...
Dim action
action = request.querystring(&quot;action&quot;)
select case action
case &quot;refresh&quot;
response.redirect(&quot;thisfile.asp&quot;)
case else
your code here
with a link to 'thisfile.asp?action=refresh'
end select
 
I'm from sweden James.

thanx for all your help. i'm really stupid u know! =)
 
hehe ok. i solved the problem to empty the whole basket but when it comes to taking the selectet merchant from the <select> box i'm stuck again. I solved it so far that it takes only 1 merchant away from the basket but it isn't the selected merchant, only the last merchant that has been put in the basket. any ideas?

björn
 
Thanx, i'll try that when i'm stop working. But i don't think that it's gonna work. But i'll try =)

thanx for all the help. How the hell have u learned so much about this?

björn
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top