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

Multiple Forms

Status
Not open for further replies.

enak

Programmer
Jul 2, 2002
412
US
I have a page that I use multiple forms on. I bring in a recordset. Each record in the recordset is displayed in a separate form on the page. I want the user to be able to make changes to any of the records and save that record.

Currently, I get the recordset and buld the page as follows:

<!-- This is WorkHistory.asp -->

do while not rs.eof
<form action=workhistory.asp?FormName=<%rs(&quot;id&quot;)%>>
<input type=submit>
</form
rs.movenext
loop

the page builds fine. But if the user makes changes to, say, the third form, how do I retrieve that data so that I can update it in the database?

TIA
Nate
 
rather than a submit button within the loop...

<form name=&quot;form<%=rs(&quot;ID&quot;)%>&quot;>
<input type=button value=&quot;Submit&quot; onClick=&quot;SubForm('<%=rs(&quot;id&quot;)')&quot;>


then write a script:

<script>
function SubForm(formID){
eval(&quot;document.form&quot; + formID + &quot;.action = 'workhistory.asp?formName=&quot; + formID + &quot;'&quot;)
eval(&quot;document.form&quot; + formID + &quot;.submit()&quot;
}
</script> -----------------------------------------------------------------
&quot;C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg.&quot;
- Bjarne Stroustrup

mikewolf@tst-us.com
 
Thanks for your reply. I did what you suggested but I get an error in the function that says:

Error: 'document.frmWorkHistory2526' is null or not an object.

I can not figure out what is wrong. Do you have any ideas?
 
check the source code that you asp produces. You should have two tags that look like:
<form name=&quot;form2526&quot;>
<input type=button value=&quot;Submit&quot; onClick=&quot;SubForm('2526')&quot;>

It sounds like there is a problem in the way you code is writing these lines....
-----------------------------------------------------------------
&quot;The difference between 'involvement' and 'commitment' is like an eggs-and-ham breakfast: the chicken was 'involved' - the pig was 'committed'.&quot;
- unknown

mikewolf@tst-us.com
 
Ok, I think the javascript is unnecessary for you to pass the data to the next page, I haven't tried it, but I am pretty sure the submit button will only submit the form it is inside. Basically what you will want to do is write the data to your page like you have above (i am adding an input to edit just for sample's sake)
Code:
<!-- This is WorkHistory.asp -->

do while not rs.eof
<form action=&quot;workhistory.asp&quot; method=&quot;POST&quot;>
  <input type=&quot;hidden&quot; name=&quot;workId&quot; value=&quot;<%=rs(&quot;id&quot;)%>&quot;>
  <input type=&quot;text&quot; name=&quot;workDesc&quot; value=&quot;<%=rs(&quot;desc&quot;)%>&quot;>
  <input type=submit>
</form
rs.movenext
loop

Pretend the above recordset is pulling data out of a table that stores id's and descriptions of the work done for that entry (you might also have dae/time etc, or if the example is to far off from what you are storing, pretend it is any text field :) )

Now on the next page you will want to update this value. Since we are directing the form back to the present page than we will want to put in some kind of flag to tell us to update this field:
Code:
<!-- This is WorkHistory.asp -->

do while not rs.eof
<form action=&quot;workhistory.asp&quot; method=&quot;POST&quot;>
  <input type=&quot;hidden&quot; name=&quot;workId&quot; value=&quot;<%=rs(&quot;id&quot;)%>&quot;>
  <input type=&quot;hidden&quot; name=&quot;next_action&quot; value=&quot;update&quot;>
  <input type=&quot;text&quot; name=&quot;workDesc&quot; value=&quot;<%=rs(&quot;desc&quot;)%>&quot;>
  <input type=submit>
</form
rs.movenext
loop

Now in our workhistory page before we select all the records and execute them into our recordset, we will want to check if there is a value for our input called next_action, in this case since the only time it will have a value is if they submit one of the forms so we only need to make sure it isn't blank:
Code:
'--- this section before you query for all the work data from the db

'If this is the first visit, ie they didn't edit anything, it will skip this section
If Request.Form(&quot;next_action&quot;) <> &quot;&quot; Then
   Dim editedId, editedDesc, sqlStr
   'only the values in the form that was submitted will be passed to this page, so we don't need to know which form it was
   editedId = Request.Form(&quot;id&quot;)
   editedDesc=  Request.Form(&quot;desc&quot;)

   sqlStr = &quot;UPDATE WorkTable SET desc = '&quot; & editedDesc & &quot;' WHERE id = &quot; & editedId

   'next execute this sql statement to update the edited record

End If

   'now continue to pull all of the data out and display your forms again, which should also display your previously edited form with the new data in it

Hope that helps, feel free to ask if there is anything you don't understand or think is questionable

-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
No more vacation for me :(

FAQ FAQ20-2863
= new Forums.Posting.General.GettingAnswers()
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top