writing onclick event in vbscript for a button created dynamically

liunx

Guest
Hi all,

I am developing a shopping cart. I wanted to pass parameters to a function written in vbscript everytime the customer clicks 'add to cart' button which is created dynamically aside each product.

could you pls tell me how to call a vbscript function and pass parameters to it .

sample code:
Response.Write("<input type='button' name='BuyNow' value='Add to Cart' onClick=''>")

assume this as the code which creates the button, now pls insert in the code that can call a function which will accept one parameter.

the procedure be: sub product(id)Originally posted by raghavan20



Response.Write("<input type='button' name='BuyNow' value='Add to Cart' onClick='product(" & rs.Fields("PRODUCTID").Value & "'>")i attach the sample code here:

this calls a simple procedure:

Response.Write("<td align='right'><input type='button' name='BuyNow' value='Add to Cart' onClick='mg()' /></td>")


<%
sub mg()
Response.Write("procedure called")
end sub

%>

this simple code doesnot call the procedure mg()

help me with this:mad:You need to exit the string as I first demostrated to you.


Response.Write("<input type='button' name='BuyNow' value='Add to Cart' onClick='product(" & rs.Fields("PRODUCTID").Value & "'>")


Notice the "&" the quote preceding that handles the terminiation of the string. The next is what is pulled from the database that is handed to the funciton. Then to complete the string with the end "'>" which makes it valid html..

there is nothing else to explain about it.How do I do the same to handle strings.

1.with your code, iam able to pass only integers, I dont know how to pass string to the client side function.

2. Is it possible to call a server side function from an input box onclick event?
Response.Write("<input type='button' onclick=<pls fill in here>>")
3. my second doubt is, when a user clicks on the add cart button that is generated dynamically, the product id which is a string should be passed to a function which then should create a dynamic Session variable which will store the cart details.

it can be represented as:

click 'addCart' button ----> function called(client-side or server side)--------->create Session object dynamically
-------->display all Session variables during 'Check out'

I have created a function in server side vbscript which creates dynamic Session objects and I am able to display dynamic Session objects.strings in javascript can be passed with single or double quotes. However if you use an onclick event and the attribute is surrounded by double qoutes you must use single inside so that it can tell its not the end of the statement. or vice versa.

No it is not possible, in the direct way your describing. It is possible in ASP.net as each item is identified by its "id" and encrypted in the viewstate.
You would have to post the the server, then route the post to a specified function depending on teh event that occured that caused it.

Use arrays. You can create an array. Using an empty variable array statement means that its intended on being used as an array but no items or length it specified.

to get the array back

ary = Session("Cart")

if isArray(ary) then
Dim intSize
intSize = Ubound(ary,2)
if intSize = 0 then
intSize = 1
else
intSize = intSize+1
end if
ReDim preserve ary(10,intSize)
end if
 
Back
Top