Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
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
?
177 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
  • 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Loops Section Overview
Suggested Courses
Course of the Month11 days, 14 hours left to enroll

564 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