I have a page that uses a session variable that stores items like a shopping cart, all this works fine but i am trying to code a button that removes an item, i have a page that i have set up for the remove function and have tried the following code - dim firstHalf, secondHalf
-
firstHalf = left(session("recordsInCart"), instr(request.form("recordNum")))
-
secondHalf = right(session("recordsInCart"), len(session("recordsInCart")) - instr(request.form("recordNum")) - len (request.form("recordNum")))
-
session("recordsInCart")=firstHalf&secondHalf
this returns an error like this
this is returning an error
Microsoft VBScript runtime error '800a01c2'
Wrong number of arguments or invalid property assignment: 'instr'
not sure where to go from here as i know nothing about this
all i want to do is click on a button on the page that will send the variable recordNum from a form on the page back to the page and remove the numbers contained in this variable
e.g.
session variable = 1,2,3,4,5,6,7,8,9
recordNum = 4
click the button and remove 4 so that the session variable = 1,2,3,5,6,7,8,9
hope i have explained this properly
13 3278
As a minimum amount of arguments, you need to provide instr() with the string to search and the string to find.
So: -
left(session("recordsInCart"), instr(session("recordsInCart"),request.form("recordNum")))
-
Looking at it though I think replace() or split() may be better options.
For example using split you could add each recordNum to an array then loop through it adding each one back to your session variable except the one you don't want.
For example -
If Not Request.Form("RecordNum") ="" Then
-
CartItems = split(session("recordsInCart"),",")
-
For Each Item in CartItems
-
If Not Item = Request.Form("RecordNum") Then newitems = newitems & Item & ","
-
Next
-
session("recordsInCart") = newitems
-
End If
-
Gaz
I understand this but it is returning an error with the sql statement that uses the session variable?? - "SELECT * FROM mp3 INNER JOIN celebs ON mp3.celebid = celebs.idnumber WHERE idnumbermp3 in (" & session("recordsInCart") & ") ORDER BY celebs.surname"
i have added a response.write on the last line and it is removing the item numbers but leaving the commas? how can i get rid of them as they must be causing the problem
any ideas it worked with the old code
Can you post here the session variable before and after the items have been removed so I can take a look see?
I probably just need to modify the loop slightly (I didn't test it!)
Never mind that.
I copied the code from here and modified it. -
<%
-
-
mytest= "1,2,3,4,5,6,7,8,9,10,"
-
-
remove = "4"
-
-
If Not remove ="" Then
-
CartItems = split(mytest,",")
-
For Each Item in CartItems
-
If Not Item = remove Then
-
If IsNnumeric(Item) then newitems = newitems & Item & ","
-
End If
-
Next
-
mytest = left(newitems, len(newitems)-1) 'remove trailing comma from each loop iteration
-
End If
-
-
Response.Write mytest
-
-
%>
-
This prduces 1,2,3,5,6,7,8,9,10 either with or without a trailing comma in the initial variable.
Just change my variables to yours.
Gaz
This is the session variable from the page previous to the delete page
0,1634,2089,1638,1633,
this is the error i get when i try and delete an item on the delete page
[Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'idnumbermp3 in (0,1634,2089,1633,,)'.
the can be seen if you follow one of the artists on the following link www.yaketyyakallmouth.com/pages/boys.asp?id=all
not sure why the 0 is at the front either but thats always been there
That now produces 0,1634,2089,1638,1633 using the modified loop in my prior post.
Can you test that now?
I now have - <%
-
-
If Not request.form("recordNum") ="" Then
-
CartItems = split(session("recordsInCart") ,",")
-
For Each Item in CartItems
-
If Not Item = request.form("recordNum") Then
-
If IsNumeric(Item) then newitems = newitems & Item & ","
-
End If
-
Next
-
session("recordsInCart") = left(newitems, len(newitems)-1) 'remove trailing comma from each loop iteration
-
End If
-
-
Response.Write session("recordsInCart")
-
-
%>
this works fine, but if i go back to another artist after deleting something it does not have a comma in the middle of the old number and the new one?
hi it now works i removed the -1
its now - <%
-
-
If Not request.form("recordNum") ="" Then
-
CartItems = split(session("recordsInCart") ,",")
-
For Each Item in CartItems
-
If Not Item = request.form("recordNum") Then
-
If IsNumeric(Item) then newitems = newitems & Item & ","
-
End If
-
Next
-
session("recordsInCart") = left(newitems, len(newitems)) 'remove trailing comma from each loop iteration
-
End If
-
-
Response.Write session("recordsInCart")
-
-
%>
just wondering if anyone could help with something else, i want to change the image of the button used to add something to the cart if it exists in the cart already
the code used to add to the cart is the following
<%
if InStr(session("recordsInCart"), ","&request.form("recordNum")) = 0 then
session("recordsInCart") = session("recordsInCart") + request.form("recordNum") &","
else
'do nothing
end if
%>
and the form that contains the button is - Response.write("<form action=""boys2.asp?id=" & yaketyRecordset("idnumber") & "&voicetype=" &voiceid &""" method=""post"">" & vbNewline)%>
-
<TD>
-
<input type="hidden" name="recordNum" value="<%=dlRecordset("idnumbermp3")%>">
-
</TD>
-
<TD><INPUT name="submit" type="image" src="../images/makeup/shortlistpink.gif" alt="Add to shortlist" align="bottom" border="0"></TD>
-
</form>
i know this must be really simple just to ask if the id number is in the session variable and then say the image is......
just not that good with asp
hi
Using my session("recordsInCart") could i find if my number stored in recordNum is in it and then change a picture depending on it, its so i can have the button that adds to the cart show a different picture if its already in the session variable
sorry ive already asked you this!!!!!
Hi
I think i understand what you mean, i have tried to code it so that depending on the Instr result it writes a different line of code for the submit button, only problem is that no button appears, im sure ive done something wrong in my code - <%
-
if InStr(session("recordsInCart"), ","&dlRecordset("idnumbermp3")) > 0 then
-
Response.Write("<INPUT name=""submit"" type=""image"" src=""../images/makeup/shortlistpink.gif"" alt=""Add to shortlist"" align=""bottom"" border=""0"">") & vbCRLF
-
else
-
Response.Write("<INPUT name=""submit"" type=""image"" src=""../images/makeup/shortlistyellow.gif"" alt=""Add to shortlist"" align=""bottom"" border=""0"">") & vbCRLF
-
end if
-
%>
For troubleshooting purposes and readability, take it out of the response.write. Usually this type of error is just a result of too many quote marks in the response.write. Remember that HTML is much more straight-forward, so if you can write it all int plain HTML do it. - <%
-
if InStr(session("recordsInCart"), ","&dlRecordset("idnumbermp3")) > 0 then
-
%>
-
<INPUT name="submit" type="image" src="../images/makeup/shortlistpink.gif" alt="Add to shortlist" align="bottom" border="0">
-
<%
-
else %>
-
<INPUT name="submit" type="image" src="../images/makeup/shortlistyellow.gif" alt="Add to shortlist" align="bottom" border="0">
-
<%
-
end if
-
%>
changed it to straight HTML and its works fine thanks for your help
Sign in to post your reply or Sign up for a free account.
Similar topics
by: DTB |
last post by:
I am trying to convert a complex function from Oracle to SQL Server
and have come across Oracle's Instr() function. I see SQL Server has
CHARINDEX() which is similar, however it does not provide...
|
by: Chris Calzaretta |
last post by:
Hello Everybody,
Question
instr function will give you the first instance of the finding
so EX:
so your string looks like
string1 = "testing>This is > just a test > testtesttest"...
|
by: Gordon |
last post by:
Hi;
I am trying to extract a substring using a combination of the mid() and
Instr() i.e.
aString = "Jones, Thomas R, Dr."
hold = InStr(1, aString, " ," , 1)
newString = Mid(aString, 1,...
|
by: Mary |
last post by:
MemberID VID
1002 1001
1003 1002
1004 1003
1005 1003
1007 1001...
|
by: fischerspooner |
last post by:
Hi,
I'm banging my head against the desk because I can't find a solution for the following simple problem.
Case: There is a column in a table that has FamilyName and FirstName(s) in one field....
|
by: rodchar |
last post by:
hey all,
i'm getting a result that i don't understand
i have a string "test1, test2"
If InStr("test1") and InStr("test2") Then
'Inside
EndIf
The inside is not running for some reason. Any...
|
by: lstrudeman |
last post by:
Hello;
A friend gave me this syntax and they are unavailable at the moment and I need this asap. I am trying to figure out how SQL figures this out. Below the syntax takes a field in a file and...
|
by: Kubie |
last post by:
I'm having problems finding the syntax/comands that do the this
correctly. I'm must not be doing the join right or something..
List one
AAC1234
CDA2w31
12ZZC12
12TRE1
23234
243
|
by: Alex Pavluck |
last post by:
I have a date stored like this '2004 - 2006' and I use this code to
get startyear and stopyear
StartYear: Trim(Left(,InStr(,"-")-1))
StopYear: Trim(Right(,InStr(,"-")-1))
Is there a way to...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |