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

need help with forms and post

Status
Not open for further replies.
Feb 3, 2003
28
US
I'm making a rating system for misc. items in our database.
What I've got so far is the opening page reads the items, gets the current rating from the database and displays them. At the end of each line/item I have 5 radio buttons valued 1-5, the strItem is populated by the db.

form method="post" action="vote.asp"
input type=&quot;radio&quot; value=&quot;1&quot; name=&quot;<%=strItem%>&quot;
input type=&quot;radio&quot; value=&quot;2&quot; name=&quot;<%=strItem%>&quot;
input type=&quot;radio&quot; value=&quot;3&quot; name=&quot;<%=strItem%>&quot;
input type=&quot;radio&quot; value=&quot;4&quot; name=&quot;<%=strItem%>&quot;
input type=&quot;radio&quot; value=&quot;5&quot; name=&quot;<%=strItem%>&quot;
input type=&quot;submit&quot; value=&quot;Vote&quot; name=&quot;B1&quot;

I've tried response.write request.form and it shows me the following posted to vote.asp:
Blue_Pen=5&B1=Vote

how do I separate the Blue_Pen and the 5 into their own variables so I can use them in the vote.asp?
 
Hi,

just type : response.write request.form(&quot;Blue_Pen&quot;) and you will get value of your check box.
 
I guess I didn't explain it right. since the strItem is coming right out of the db I don't know what the value will be when its passed. Do you mean I have to write something that will take into account every item in the db? Say I have 100 items in the DB, I have to write a line for each?
 
Let me see your code in txt format
If you post it on here wrap it with
Code:
 
ok here's what if got, I've cut out what doesn't matter for what I'm asking. Is this what you need?

< attach to datebase >

Do While Not rsCounter.EOF

strItem = rsCounter.Fields(&quot;item&quot;).Value

response.write rsCounter.Fields(&quot;real_name&quot;).Value
response.write rsCounter.Fields(&quot;description&quot;).Value

form method=&quot;post&quot; action=&quot;vote.asp&quot;
input type=&quot;radio&quot; value=&quot;1&quot; name=&quot;<%=strItem%>&quot;
input type=&quot;radio&quot; value=&quot;2&quot; name=&quot;<%=strItem%>&quot;
input type=&quot;radio&quot; value=&quot;3&quot; name=&quot;<%=strItem%>&quot;
input type=&quot;radio&quot; value=&quot;4&quot; name=&quot;<%=strItem%>&quot;
input type=&quot;radio&quot; value=&quot;5&quot; name=&quot;<%=strItem%>&quot;
input type=&quot;submit&quot; value=&quot;Vote&quot; name=&quot;B1&quot;

rsCounter.MoveNext
Loop

< close connections and clean up>
 
Give all the buttons the same name.

Make value=&quot;<%=item(&quot;uniqueitemID&quot;)%>&quot;

Then when you grab the button value in the next page, you have have the ID that has been checked.

Steve Davis
hey.you@hahaha.com.au

Me? I can't even spell ASP!
 
just to clarify, that would be

<input type=&quot;radio&quot; value=&quot;<%=item(&quot;uniqueitemID&quot;)%>&quot; name=&quot;somename&quot;><%=strItem%>

Steve Davis
hey.you@hahaha.com.au

Me? I can't even spell ASP!
 
ok, I get what your saying. But, I need to pass two values, one being the name(strItem value from db) and the value (1-5) they selected. If I change the button name to val and the value to strItem I'll be missing the value they selected (1-5)
If I do a response.write request.form(&quot;val&quot;) on the other page I'll get
val=(strItem value from db)&B1=Vote

correct? or am I not even in the ball park?
 
Aha...

make the name of the button the strItemID and the value the vote weight.

<input type=&quot;radio&quot; name=&quot;123&quot; value=&quot;3&quot;>
^ ^
itemID vote weight


How you handle it from there depends on how many things are being voted on. If it was only one, then I would have the form action be 'update.asp?itemID=<%=items(&quot;itemID&quot;)' and find the record that way (or just get it from the button name).

If you are voting on more than one item, loop through the names of the buttons and update the fields one at a time.


Steve Davis
hey.you@hahaha.com.au

Me? I can't even spell ASP!
 
Why don't you store the name of the field in a separate variable and use counters to find out how many values you have. Something like this:

<%

' Connect to Db and get data

Dim count : count = 0

' Start the form outside the loop
Response.Write &quot;<form method=&quot;&quot;post&quot;&quot; action=&quot;&quot;vote.asp&quot;&quot;>&quot;

Do While Not rsCounter.EOF

count = count + 1
strItem = rsCounter.Fields(&quot;item&quot;).Value

response.write rsCounter.Fields(&quot;real_name&quot;).Value
response.write rsCounter.Fields(&quot;description&quot;).Value
%>

<INPUT TYPE=&quot;HIDDEN&quot; NAME=&quot;ITEM<%=count%>&quot; VALUE=&quot;<%=strItem%>&quot;>
<input type=&quot;radio&quot; value=&quot;1&quot; name=&quot;VALUE<%=Count%>&quot;>
<input type=&quot;radio&quot; value=&quot;2&quot; name=&quot;VALUE<%=Count%>&quot;>
<input type=&quot;radio&quot; value=&quot;3&quot; name=&quot;VALUE<%=Count%>&quot;>
<input type=&quot;radio&quot; value=&quot;4&quot; name=&quot;VALUE<%=Count%>&quot;>
<input type=&quot;radio&quot; value=&quot;5&quot; name=&quot;VALUE<%=Count%>&quot;>

<%
rsCounter.MoveNext
Loop
%>

<INPUT TYPE=&quot;HIDDEN&quot; NAME=&quot;numItems&quot; VALUE=&quot;<%=count%>&quot;
<input type=&quot;submit&quot; value=&quot;Vote&quot; name=&quot;B1&quot;>



Then in your processing page simply loop through the list of items:

for i = 1 to CInt(Request.Form(&quot;numItems&quot;))

item = Request.Form(&quot;ITEM&quot; & i)
value = Request.Form(&quot;VALUE&quot; & i)

next

From the loop above, you can see how easy it is to see what item is being rated and what rating it is getting.

Hope that helps and is not too complicated.

Mighty
 
ok ,so either it's too late and I'm tired or my server is acting up. I have followed the advice from Mighty (thank you!), all the values I'm looking for are now being passed to the other page. Here's what I get when trying to hit the DB to find the record and update it.

Microsoft VBScript runtime error '800a01a8'

Object required: &quot;

/test/asp/ratings/vote1.asp, line 31

I know what this means but I cannot find what's wrong. Now here is the code I have. It's been cut and pasted from the other pages I've used over and over.It's been edited for what I need on this page. This is line 31 and in the code it's all on one line.

rsCounter.Open strSQL, &quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=&quot; & Server.MapPath(&quot;counter_db.mdb&quot;) & &quot;;&quot;, adOpenKeyset, adLockPessimistic, adCmdText

the strSQL values I have tried:

strSQL = &quot;SELECT item, total_votes, rating FROM hit_count WHERE item=&quot; & Request.Form(&quot;ITEM&quot;) & &quot;;&quot;

strSQL = &quot;SELECT item FROM hit_count WHERE item='&quot; & Request.Form(&quot;ITEM&quot;) & &quot;' ;&quot;

strSQL = &quot;SELECT item FROM hit_count ;&quot;

all give me the same error above! What am I missing? I know at least one of the strSQL lines is correct because I've used it on another page and it works. I'm going to try again this evening but I figured I'd ask
 
hmm... i am not sure abt the problem.
but a good practice when u retrieve data from database is to trim it first.... because it always return some null character from database.
 
the only thing I do the rsCounter is
Dim rsCounter

That's it. Like a said, I've used this in other pages with the same setup. All of those pages work fine..
 
sorry, completely missed my line

I have
Set rsCounter = Server.CreateObject(&quot;ADODB.Recordset&quot;)
right before the line
rsCounter.Open strSQL, &quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=&quot; & Server.MapPath(&quot;counter_db.mdb&quot;) & &quot;;&quot;, adOpenKeyset, adLockPessimistic, adCmdText

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top