Im trying to send some checkbox values as an array and then insert it to my database, but I can't get the array values into variables in my asp page?
I want to get the array values into variables kalnr0=arrayvalue0, kalnr1=arrayvalue1 etc…
I have this now: And it shows the alert(texten) that say its an array.
Im sending the form with ajax method="GET"
and the form field:
<input type="checkbox" name="kalendrar_id[]" value="<%=rs("kalendrar_id")%>">
and on my receiving asp page I have this:
Dim kalendrar_id
kalendrar_id=request.querystring("kalendrar_id[]")
kalitem = Split(kalendrar_id, ",")
japp=array(kalitem)
If IsArray(japp) then
For i = 0 To UBound(kalitem)
On Error resume next
Response.Write kalnr(i)=i
Next
texten= " is an array"
Else
texten= " not an array"
End If
So how do I get the array values into the below variables?
kalnr0=Cstr(kalitem(0))
kalnr1=Cstr(kalitem(1))
kalnr2=Cstr(kalitem(2))
kalnr3=Cstr(kalitem(3))
kalnr4=Cstr(kalitem(4))
I really need some help with this, thanks :-)
If I set kalendrar_id="1,2,3,4,5" then it works, so kalendrar_id=request.querystring("kalendrar_id[]") is not getting any value, or its the wrong value!?
And if I post the form the normal way, not with ajax then it works, so somehow the query string request.querystring("kalendrar_id[]") is wrong, could it be something with encoding?
SOLVED. I had to remove [ ] from the form field, not sure what else, have tried so many things ;-)
First off, if your question is how to put something like the following into a loop...
var1 = var(1)
var2 = var(2)
...
var5 = var(5)
... the answer is don't do that. :) ("Doctor, it hurts when I press here." "So don't press there.")
Second, you don't need to use both Split() and Array(). Split() already produces an array, so the second function isn't doing anything useful.
Third, I'm not sure why you're using square brackets in the field names. If you think they'll somehow magically make your form return an array, well, they won't. All they'll do is make some servers eat your form results. (Not all servers, which is why square brackets are allowed in form field names, but they're still not a good idea, especially with method="get".)
To debug an issue like yours, the first thing to try is to look at what the form is returning. With method="get", you could just look at the querystring in the address bar, but it's better to explicitly see what the server thinks it's getting:
Response.Write "fieldname=" & Request.Querystring("fieldname") & "<br>"
If that doesn't get you what you expect, then you need to make sure the form field is actually named what you think it is. If yes, the next step is to double-check that the form is getting filled out - i.e. is the reason it's not returning a value the fact that there's no value to return?
Related
Ok, here's my use case. I have a form that pulls different parts of the form from a number of tables in a database. Each time I pull the info, I test to make sure there were no errors. Currently I'm using msgbox to show if there are errors, but I'm rewriting the app to instead display these messages in a "status" line area. It's just a label that I write the strings into on the form that flashes the error. This is working great in my single "You did this, and you got an error" forms. But in one of my forms it's about 6 things that could give errors, and it's on load. So it's not a single action, single error type deal.
My idea is to load any errors into an array, then display them one at a time for like 5 seconds each, then loop back and do it again, for at least 5 times. So in effect I want it to show each error, for 5 seconds, then show the next one for 5 seconds, then start over again, for 5 times, then stop.
Problem is, while I've got about 10 ideas on ways to maybe do this, they all seem really complicated and complex (and I don't want to spend 10 hours writing it only to figure out it's not going to work). I'm looking for the "best" way.
So.... Is an array even the best way? Or would a list or some other way be better? I'm looking for ideas here. How would YOU do it?
Eventually, you can use arrays for what you are trying to achieve. This could be done by following the steps :
When you are pulling the information from the tables, check for errors and if there is any, put it into an array.
Define a for loop which is going to loop 5 times
Define another nested loop to loop through the array to display the messages one by one
After each message display, put a sleep or delay of 5 seconds
If you follow these instructions, it just a matter of minutes into writing the codes
I ended up solving this by using a combobox and a list, then just having my combobox blink. On forms that can only throw one error, I use a label instead. Here is the lion's share of my code to do this:
Private Sub ErrorCheck()
If errorList.Count = 1 Then
ErrorComboBox.Visible = True
DismissErrorButton.Visible = True
For Each errors As String In errorList
ErrorComboBox.Text = (errors)
Next
ErrorBlinkTimer.Enabled = True
ElseIf errorList.Count > 1 Then
ErrorComboBox.Visible = True
DismissErrorButton.Visible = True
ErrorComboBox.Text = "There were errors, click drop down to view!"
For Each errors As String In errorList
ErrorComboBox.Items.Add(errors)
Next
Else
End If
End Sub
What I do is after each thing in a SUB that can throw errors, I have it collect the error and write it to errorList with errorList.add like so:
Catch ex As Exception
Dim errorStr = "An Error Occurred in " & Me.Name & " writing into the OpenEvents table " _
& "for setting the Alert radio button."
log(errorStr & " - " & ex.Message)
errorList.Add(errorStr)
the log function is a custom function for writing off to the log, but the rest is standard VB.net stuff. As you can see, if I get any exception (I do the same thing with each query too) it writes the error off to the errorList, then flashes the combobox with the error(s). I have some more logic to make it all nice and pretty, but you get the idea.
at the end of each sub that CAN throw errors, I just have it call:
ErrorCheck()
and like magic, if there were any errors a combobox list appears with bright red flashing text to let them know. If they click it, and there is more than one error, they can see them all in a nice list. Clicking it also makes it stop flashing, cause that would be annoying... LOL
This ended up working much better overall really, but it's not quite as pretty as my first way of doing it... but, no matter what I did, it caused issues on the form(s) to have it running through the flashing loop 5x's to display each error one after the other. I had found work arounds for most of it, but there was still a performance impact, so I dumped it for this. And it does the job well enough.
Is there an easy way to update a field on a get of a get_or_create?
I have a class ItemCategory and I want to either create a new entry or get the already created entry and update a field (update_date).
What I do is:
item,created= ItemCategory.get_or_create(cat=cat_id,item=item_id)
if created == True:
print "created"
else:
item.update_date = datetime.now
item.somethingelse = 'aaa'
item.save()
This works for a while in my loop. But after 50-100 get/create it crashes:
peewee.InterfaceError: Error binding parameter 4 - probably unsupported type.
Maybe I should use upsert(), I tried but wasn't able to get anything working. Also it's not probably the best solution, since it makes a replace of the whole row instead of just a field.
I like peewee, it's very easy and fast to use, but I can't find many full examples and that's a pity
Newbie mistake
item.update_date = datetime.now()
I am not 100% sure this is the only answer though. I modified my code so many times that it might be also something else.
Regarding my question about create_or_update , I've done this:
try:
Item.create(...)
except IntegrityError:
Item.update(...)
peewee is really great, I wonder why no one ever asked for a create_or_update.
I am currently having trouble filling up an array of customClass.
I try to fill it with a jsonFile. During my json parsing (using swiftyJSON) i loop and fill my array.
The problem is, at the end of my loop, it is still empty. I tested it in different ways, and here is my code:
That's the file where the problem is. In my loop I fill an Annotation, that I add with append to my array. The problem is what my print return. Here is a part of it:
It's just a small part of a huge jsonfile. And, my tmpAnnot.name is correctly printed every iteration. But when it comes to my Array, nothing.
So I'm completly lost and hope you could help me ^^
(And for the information, here is my custom class) :
And btw, I tried to print my array.count, and it's nil too
Im so sorry if the question has been posted. I couldn't find it in the entire website.
Change your JSONAnnotationList declaration to be an non-optional and assign it an empty array
var JSONAnnotationList: [UGOAnnotation] = []
You see, you have never created an array so there was nothing to be printed.
The whole point of optionals is to use them sparingly, not everywhere.
I need to assign data field (component of another field symbol) to field-symbol in a several places of code. For the sake of reusability I decided to encapsulate this code in procedure, but I cannot understand how to pass field-symbols into this procedure.
LOOP bseg ASSIGNING <bseg>
...
PERFORM assigning USING <bseg>
CHANGING <wrbtr>.
...
ENDLOOP.
FORM assigning USING <bseg> TYPE bseg
CHANGING <wrbtr> TYPE bseg-wrbtr
IF ...
some logic here
ASSIGN <bseg>-wrbtr TO <wrbtr>.
ELSE
ASSIGN <bseg>-skfbt TO <wrbtr>.
ENDIF.
ENDFORM.
This code does not work.
What should I do to change the field symbol reference too?
This is not possible, at least not the way you try to do it. Field symbols cannot be passed as the pointers they really are. If you need something like that, you'll have to use real references.
Not knowing anything about the rest of your code - it looks a bit weird. Why would you want to change data in BSEG fields directly? I can only assume that you're "abusing" fields to transport some custom value throughout the code, and that's usually a bad idea. And if you need to do this, I'd rather do it this way:
LOOP bseg ASSIGNING <bseg>.
IF foo.
l_my_wrbtr = <bseg>-wrbtr.
ELSE.
l_my_wrbtr = <bseg>-skfbt.
ENDIF.
" ... pro'lly thousands of lines I don't even want to see...
IF foo.
<bseg>-wrbtr = l_my_wrbtr.
ELSE.
<bseg>-skfbt = l_my_wrbtr.
ENDIF.
ENDLOOP.
I did a separate levelData class to be able to flexibly add levels. I was happy with it until my supervisor ordered me to convert my levelData into XML. I did an XML version of the levelData's data (question, answers, correct answer...). I used the old class and converted it so that it fetches the XML.
All seems well, I did traces of my answers array and it printed nicely...
But the headache started when I tried this.
// This code appears in a different class with
// currentLvl:LevelData initialized in the constructor.
quizHolder.ansA.ansHud.text = currentLvl.choices[1];
quizHolder.ansB.ansHud.text = currentLvl.choices[2];
quizHolder.ansC.ansHud.text = currentLvl.choices[3];
quizHolder.ansD.ansHud.text = currentLvl.choices[4];
// BTW, I can't make a for loop to do the same function as above. So wierd.
I tried to run it. it returned:
TypeError: Error #2007: Parameter text must be non-null.
at flash.text::TextField/set text()
at QuestionPane/setQuiz()
at QuestionPane/setQuestion()
at QuestionPane()
at LearningModule()
Where did I go wrong? I tried making a custom get function for it, only to get the same error. Thanks in advance. If I need to post more of the code, I will gladly do so =)
LevelData Class in PasteBin: http://pastebin.com/aTKC1sBC
Without seeing more of the code it's hard to diagnose, but did you correctly initialize the choices Array before using it? Failing that I think you'll need to post more code.
Another possible issue is the delay in loading the XML data. Make sure your data is set before QuestionPane tries to access it.
When did you call
quizHolder.ansA.ansHud.text = currentLvl.choices[1];
quizHolder.ansB.ansHud.text = currentLvl.choices[2];
quizHolder.ansC.ansHud.text = currentLvl.choices[3];
quizHolder.ansD.ansHud.text = currentLvl.choices[4];
these? You load the XML and on complete you fill the array, what is correct. but is the XML loaded and parsed to the time when you access (fill the TextFields) the choices array already?