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!

sending data

Status
Not open for further replies.

penguinspeaks

Technical User
Nov 13, 2002
234
0
16
US
Hello everyone.

I am going to try and explain what I need, what the code is doing, and how I may injure myself due to the frustration.

I have a table of records returned from my query of the database table. This is fine and dandy. I am wanting to have some dropdown boxes on the table for the purpose of updating a person's status. I have placed a dropdown list for this purpose.
The problem is when this gets submitted, it sends the valuses for all records returned and not just the one I wish to update. I have the "ID" in a hidden field so the asp processing page knows which record should be updated but when I response.write id on that page, it shows every id returned fopr that query.

Here is the code

Code:
<form name="form1" action="statuschangeasp.asp" method="post">

	<tr style bgcolor="<%=rowcolor%>">
		<td class="auto-style2" ><%=orders1.fields.item("id").value%></td>
		<td class="auto-style2" >
		<span id="c10_ctl">
		
		<select  onChange="document.form1.submit()" name="change_">
		<option selected="<%=orders1.fields.item("istatus_").value%>" value="<%=orders1.fields.item("istatus_").value%>"><%=orders1.fields.item("istatus_").value%></option>
		
		<option value="Shipped">Shipped</option>
		<option value="Sent">Sent</option>
		<option value="paid1">Paid PayPal</option>
		<option value="paid2">Paid Check</option>
		<option value="received">Received</option>
		<option value="processing">Processing</option>
		<option value="processed">Processed</option>
		<option value="returned">Returned</option>
		<option value="Pending">Pending</option>
		</select>
			<input name="id" type="hidden" value='<%=orders1.fields.item("id").value%>'/>
			
			</span>
			</td>
		<td class="auto-style2" ><%=orders1.fields.item("tracking_").value%></td>
		<td class="auto-style2" ><%=orders1.fields.item("first_").value%></td>
		<td class="auto-style2" ><%=orders1.fields.item("last_").value%></td>
		<td class="auto-style2" ><%=orders1.fields.item("state_").value%></td>
		<td class="auto-style2" ><%=orders1.fields.item("email_").value%></td>
		<td class="auto-style2" ><%=orders1.fields.item("phone_").value%></td>
		<td class="auto-style2" ><%=orders1.fields.item("mod1_").value%></td>
	</tr>
	
<% 
irowcolor = irowcolor + 1
orders1.movenext
loop
else
%>
</form>

the result should be whatever the change is on the dropdown, along with the id for that record. this is what the response.write for the status_ and the id look like.

Code:
processing, shipped, pending, shipped, pending, shipped, shipped, shipped, shipped, shipped, shipped, shipped, pending, pending, pending93, 100, 103, 105, 106, 108, 109, 115, 119, 120, 121, 123, 126, 127, 128


any ideas?
 
If this should be asked in a different forum, please let me know that as well.
 
The select control has the same name (change_) on each row, so when you request it, it's giving you the values it finds on every row. So give each select a different name. Since you say you will know the id from a hidden field, attach the ID number to the name of each select like below, then request "change_" plus the ID number.

[pre]<select onChange="document.form1.submit()" name="change_[highlight #FCE94F]<%=orders1.fields.item("istatus_").value%>[/highlight]">[/pre]

 
I understand what you are saying but I do not follow, if you will.

Each row contains the form, yes, but it is only getting submitted from a single row containing specific records from the loop. So I would think that the values of the form were based on the record in the loop and not all of the records.

I am confused.
Anyhoo, I have tried your idea and it brings up a question.

If I change the name to name="change_<%=orders1.fields.item("istatus_").value%>" How do I capture this on the processing page?
Code:
statuschange_ = request.form("change_")&id
does not seem to work.
 
Also, this still sends all of the "id" from the hidden field as well.

This just seems so basic and I cannot figure it out. I have done this in the past but cannot remember.
 
I am thinking about this and I believe it is the form name being the issue. The "onchange" is submitting each form with that name. I think I need to change the form name to be dynamic with record and only submit that.

possible?
 
No, you have one row per database record. Each row (TR tag) contains 9 cells (TD tags), the second of which is a dropdown (SELECT tag) that is supposed to relate to the status of that record. Presumably you are enclosing all these rows (TR tags) inside a table (TABLE tag... which I don't see here). And that entire table would be inside one form (FORM tag). The code you posted is either incorrect or incomplete.

Given that scenario, every time you change any of the SELECT boxes to a different option, the ENTIRE form is being submitted (onChange="document.form1.submit()"). At this time, you can request values any or all the form fields you created.

How do I capture this on the processing page?

[tt]statuschange_ = request.form("change_" & id)[/tt]
 
Something like this is what I'm referring to. This is not working code, just giving you an idea of what i mean
Code:
<form name="form1">
<table>

<%sql = "SELECT * FROM myorders WHERE something = true"
orders1.Open sql, Connectionstring
Do while not orders1.eof
%>
   <TR>
      <TD><%=orders1.fields.item("id").value%>
      <TD><select onChange="document.form1.submit()" name="change_<%=orders1.fields.item("id").value%>">
         <option>Shipped
         <option>Sent
         <option>etc
         </select>
<% 
   orders1.movenext
loop
orders.close
%>   

</table>
</form>
 
Oh ok....

Give your hidden field an ID:
[pre]<input [highlight #FCE94F]id="statusid"[/highlight] name="[highlight #FCE94F]statusid[/highlight]" type="hidden" value='<%=orders1.fields.item("id").value%>'/>[/pre]

Change your onchange to:
[pre]onchange="[highlight #FCE94F]document.getElementById('statusid').value='<%=orders1.fields.item("id").value%>';[/highlight]document.form1.submit();"[/pre]

I'm doing this quickly so sorry in advance if I'm getting anything wrong; not tested, but this should store the ID number of the changed select box in the hidden value (that I renamed statusid). Again, typing fast but something like this should work:
[pre]statuschange_ = request.form("change_" & request.form("statusid"))[/pre]
 
Actually, for the hidden field:
[pre]<input id="statusid" name="statusid" type="hidden" value="">[/pre]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top