?
Solved

How to pass a variable from a recordset to another form using a button inside the form

Posted on 2005-04-05
5
Medium Priority
?
174 Views
Last Modified: 2013-12-24
hi

I built a simple query that retrieves some data.
Using that query (recordset1) I built with Dreamweaver MX 2004
a Dynamic Table that displays the recordset (name, surname, address).
It works fine so far.

All the dynamic table is placed inside a form and on  the right side
of the dynamic table, I put in a cell, a button which will
allow me to load the book3.cfm when I click to it. For example if the
query returns 5 records, so on the right side 5 buttons will be displayed.

How can I pass a variable (for example the surname) from the recordset
on the next page (book3.cfm) and display it from the specific button i clicked ?
 (well I actually want to use it so if I display it someway I can use it also)

I tried using a hidden field but then on the next page it displays always
the first name of the people retrieved and not actually the one I clicked :-(
I cannot understand that because the hidden field is placed outside the
dynamic table but inside the form (I tried it inside with and displayed all names hhahahah)

Thank you a lot.
0
Comment
Question by:brakos
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 15

Assisted Solution

by:DanielSKim
DanielSKim earned 375 total points
ID: 13707407
The easiest way to do this is to name the submit buttons the same, but give a different value (the surname?) for each button.

example:

<form action="book3.cfm" method="post">
<input type="submit" value="LastName1" name="ButtonValue">
<input type="submit" value="LastName2" name="ButtonValue">
</form>

then on book3.cfm, you would retrieve the value with:
#Form.buttonvalue#

the only drawback with this method is that the value you specify will be the value displayed by the button.

another way to do this is with the names of the buttons.

<form action="book3.cfm" method="post">
<input type="submit" value="Detail" name="LastName1">
<input type="submit" value="Detail" name="LastName2">
</form>

if you have no other fields you are sending, you can retrieve the name of the button by referring to this:

#Form.FieldNames#

Let me know if you have any questions.
0
 
LVL 15

Accepted Solution

by:
DanielSKim earned 375 total points
ID: 13707530
a note: the suggestions above and below use static examples. instead of using names like LastName1, b_LastName1, etc., you would be inserting results from your recordsets.

some other suggestions . . .

if you have other form fields you are sending, you can do something like this:

<form action="book3.cfm" method="post">
<input type="text" name="TextBox">
<input type="submit" value="Detail" name="b_LastName1">
<input type="submit" value="Detail" name="b_LastName2">
</form>

on the book3.cfm page, if you refer to #Form.FieldNames#, you will see either:

Textbox,b_LastName1

or

Textbox,b_LastName2

depending upon which button you clicked.

You can loop through each of the fieldnames until you come across one that is prefixed with a "b_".

<!--- code on book3.cfm --->
<cfloop from="1" to="#ListLen(Form.FieldNames)#" index="i">
  <cfif Left(ListGetAt(Form.FieldNames, i),2) EQ "b_">
    <cfset buttonName = ListGetAt(Form.FieldNames, i)>
    <cfset buttonvalue = Right(buttonName, Len(buttonName) - 2)>
  </cfif>
</cfloop>
<cfoutput>#buttonvalue#</cfoutput>

if you don't want to send any form data, instead of buttons, you may want to create links:

<a href="book3.cfm?"LastName=LastName1>Some Text1</a>
<a href="book3.cfm?LastName=LastName2">Some Text2</a>

so, on book3.cfm, you would reference:

#URL.LastName#
0
 
LVL 20

Expert Comment

by:trailblazzyr55
ID: 13708587
<cfquery name="YourQR" datasource="YourDSN">
SELECT name, surname, address
FROM yourTable
</cfquery>

<FORM NAME="YourForm" ACTION="" METHOD="post">
<Table>
    <TR>
         <TD align="center">Name</TD>
         <TD align="center">Last Name</TD>
         <TD align="center">Address</TD>
         <TD align="center">Go</TD>
    </TR>
<cfoutput query="YourQR">
    <TR>
        <TD>#name#</TD>      
        <TD>#surname#</TD>
        <TD>#address#</TD>
        <TD><input type="button" name="???" onclick="this.form.action = 'book3.cfm?name=#name#&surname=#surname#&address=#address#';">
             </TD>
    </TR>
<cfoutput>
</Table>
</FORM>

This will submit what ever info you click on to the next page...

Hope that helps
0
 
LVL 20

Expert Comment

by:trailblazzyr55
ID: 13708605
so now you can get the info on your action page as #name# #surname# #address# or however you want to display it but it will be the info you click the button for.

regards,
~trail
0
 

Author Comment

by:brakos
ID: 13760415
thanks guys
0

Featured Post

Portable, direct connect server access

The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question