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

buttons with same name that pass different value 2

Status
Not open for further replies.

nuct

Programmer
Sep 5, 2001
103
Hi, I have a form with a list, I want to put an "edit" box next to each item on the list so it can be edited.

How do I make it so that the visible name of the edit button is alwats "edit" but the value that is passed to the edit page is the id of the item on the list.

Its not the ASP side of things Im having problems with its the HTML. Specifically I havn't got a clue which tag options to use in the INPUT tag.

Cheers,
Simon.
 
that 'box' on the first line is suppost to be button

Sorry
Simon.
 
<input type="button" name="edit1" value="Edit" />
<input type="button" name="edit2" value="Edit" />


something to that effect...
 
Unfortunatly that doesn't work. Now the buttons don't do anything. Do I have to put something in the form tags? If I change the type to "submit" the buttons take you to the desired page but the parameter line in the URL is like:

?edit2=edit

instead of

?edit=1 or ?edit=2 etc... depending on the button clicked.

Any ideas?
Simon.
 
Something like?:

<%
X=0
While Not RS.EOF
Response.Write "<form name=""pending"&X&""" method=""Post"">"

%>
<tr><td><input type="hidden" name="ticket" value="<%=RS("ticket")%>"></td></tr>
<tr>
<td><font face="arial,verdana" color="#000000" size=2><center><%=RS("ticket")%></td>
<td><font face="arial,verdana" color="#000000" size=2><center><%=RS("cust")%></td>
<td><font face="arial,verdana" color="#000000" size=2><center><%=RS("origdate")%></td>
<td bgcolor="#E4EAF5"><input type="submit" value="View" onClick="this.form.action='default_ctsdetails.asp';"></td>
<td bgcolor="#E4EAF5"><input type="submit" value="Cancel" onClick="javascript:query(<%=X%>);"></td>
<%
Response.Write(" <td bgcolor=""#E4EAF5""><input type=""submit"" value=""Edit"" onClick=""this.form.action='default_ctsedit.asp';""></td>")
%>
</tr>
<%
Response.Write "</form>"
X=X+1
RS.MoveNext
Wend
%>
 
How about just a hidden field? In fct you could use a hidden field on each line and allow the user to update changes for the entire listing rathe then one record at a time...

If you want to allow editing one row at a time you can name your fields with the id as part of the name, then use the onClick of the button on each row to place the number for tat row into a hidden field:
Code:
<form method="POST" action="mySecondPage.asp" name="frmEdit">
<input type="hidden" name="edit" value="">
<table>
<%
Do Until myRS.EOF
   %>
   <tr><td>
   <input type="text" name="Field1_<%=myRS("id")%>" value="<%=myRS("Field1")%>">
   </td><td>
   <input type="button" onClick="frmEdit.edit.value='<%=myRS("id")%>';frmEdit.submit();" value="Edit">
   </td></tr>
   <%
   myRS.MoveNext
Loop
%>
</table>
</form>
So basically I assumed you had an id field in your recordset, but you coud just as easily use a counter. Since you named your field based on the id and then pass the id in the 'edit' input, on your next page you could retrieve the Field1 value by doing this:
Code:
If Request.Form("edit") <> "" Then
   edit_id = Request.Form("edit")
End If

Response.Write "You wanted to edit this field: " & Request.Form("Field1_" & edit_id)

Now, if you wanted to be able to modify multiple rows and update them all then I would suggest to still name each field in the row based on the id for that record (or a row counter variable), but to place a hidden field in each row with the id for that row and the same name for each row (this will pass them all as a comma-delimited list). On the next page you woul simply doa for each loop on the value of the hidden fields and in each loop pull out the values rom the previous page by concatenating each id with the base field names.

If I remember correctly Ibelieve I put an example of editing multiple items at nce in a table in the FAQs section (ASP 102?)

-T

barcode_1.gif
 
You can do it without client-side script. You just want the type to remain "submit", not "button":
Code:
<form method="POST" action="mySecondPage.asp" name="frmEdit">
    <input type="submit" name="edit" value="edit1" />
    <input type="submit" name="edit" value="edit2" />
</form>
And on the server, Request.Form("edit") will be equal to the button pressed.

Standard HTML behavior, nothing magical necessary. ;-)
 
D'oh! Sorry, those end up with different names. It was only after re-reading the title of your question that I realized I had answered an entirely different question. :)
 
The problem with changing the value of the button is that it is then displayed to the end user, so you get sales people asking what all that gibberish is on the buttons when it should say "Edit" :p

A std HTML solution would be to make each row a form by itself and not mess with crazy naming techniques. This would work but would likely double the download time of the file...

barcode_1.gif
 
Personally I just handle it in a way that the vast majority of users will understand intuitively, and have a radio button on each row with the ID as the value to select the record.

then you can have submit buttons for edit, delete, view or any other function needed.

You could also have a onClick event for the radio buttons to enable/disable the submit buttons.

the id and the button value is retrieved then use include, redirect or transfer accordingly.



Chris.

Indifference will be the downfall of mankind, but who cares?
A website that proves the cobblers kids adage.
Nightclub counting systems

So long, and thanks for all the fish.
 
And the way I usually do it -- if it's an editing interface -- is have the name of the item be the link to the editing of that item, with a delete link (not button) next to each item. It seems intuitive to click on the thing to "go to it," to me, so if the only "going" is editing, you're set.
 
Cheers for the response, most helpful, I used Tarwns way in the end.

Simon
 
just a follow up note..
i try to avoid relying on client side scripting, in case of old broswers, security settings, or some goofy browser type i didn't take into consideration

alternate method.. it ends up increasing the output side of the page a little (not dramatically, taking into consideration the onclick stuff):

{style is to help avoid the blasted form gaps}
Code:
<style>
FORM {margin:0;
margin-top: 0px; 
margin-bottom: 0px;}
</style>

<table>
<%do while not rs.eof%>
    <tr>
        <td><%=RS("Description")%></td>
        <td>
            <form method="post" action="blah.asp">
                <input type="submit" name="Edit" value="Edit">
                <input type="hidden" name="recID" value="<%=RS("ID")%>">
            </form>
        </td>
    </tr>
<%rs.movenext
loop%>
</table>

[thumbsup2]DreX
aKa - Robert
if all else fails, light it on fire and do the happy dance!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top