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

Textbox Entry - Set as Two Variables 2

Status
Not open for further replies.

sysadmin07

IS-IT--Management
Feb 20, 2007
41
US
Hi,

I'm trying to send a user-entered field from a textbox into two ColdFusion variables. For example, if I have
<input name="test"> and I want it to also equal "test2", how would I go about setting them equal?

Thanks.
 
Can anyone please help? I've looked everywhere, but cannot find any examples.

Thanks.
 
On the action page just set the variable to the form value.

ON FORM PAGE:
<input name="test">

ON ACTION PAGE:
<cfset test1 = "#FORM.test#">
<cfset test2 = "#FORM.test#">

If this is not what you need then please give more info so we can help better...

_____________________________
Just Imagine.
 
Thanks for the help. I've tried your suggestion, but I'm getting a "Variable TEST is undefined" error. Test and Test1 are getting written to a database, so should I modify the notation for this?

I've written it as shown below and also tried it your way, to no avail:

ON FORM PAGE:
<input name="test">

ON ACTION PAGE:
<cfset "#test1#" = "#FORM.test#">
 
You can't do something like cfset "#test1#". Test1 has to be the variable name, not a variable itself. Why do you have the cfset as #test1#?

_____________________________
Just Imagine.
 
I have cfset as #test1# because it's the name of the database record that I'm trying to set equal to #test#.

Thanks.
 
Tried about every combination I could think of, but nothing is happening. Here are some details:

-Form page
-Page name is formtest
-<input name="test">

-Action page (separate CF page, btw)
-<cfset test1 = "#formtest.test#">

Is this correct? If so, I can't get it working.

Thank you for your help.
 
I have cfset as #test1# because it's the name of the database record that I'm trying to set equal to #test#.

Are trying to see if the FORM.test value matches #test1# (which is a dB record)? What do you plan on doing if the values match?

Why not do a <cfif>?

<cfif #queryName.test1# EQ #FORM.test#>
Record matches
<cfelse>
Does not match
</cfif>

_____________________________
Just Imagine.
 
I always want them to be equal, so I don't need a cfif (thanks for the suggestion though). For example, if "hello" is entered into the "test" textbox, I want "test1" to also have that value; so when they're written to my database, both fields will have equal values.

Thank you
 
Code:
<cfset test1 = "[red]#formtest.[/red]test#">

Should be, regarless of the name of the page before:
Code:
<cfset test1 = [green]form.test[/green]>

[green]form[/green] is a variable scope, [red]formtest[/red] is a page name which coldfusion doesn't need or care about.

[plug=shameless]
[/plug]
 
After setting them equal using <cfset test1 = form.test>, I'm trying to set a textbox's value to test1. I can't seem to get it to output correctly. I've tried every combination I can think of (e.g. value="#test1#"). What am I doing wrong?

Thanks
 
Will the checkbox be checked as well? Or, just set the value of the it to #test1#?

Show us some code you've done so far and we can help tweak it.

_____________________________
Just Imagine.
 
If the variables are only used for inserting the value of #form.test# into the two db columns, why use variables at all?

Example1:
INSERT INTO db_TBL(test1,test2)
VALUES('#form.test#','#form.test#')

Only if there will be further need to manipulate the values (ie.. using a CF Function to add, remove, change the value in any way) do you really need to set a variable.

Example2:

<cfset test1 = "#FORM.test#">
<cfset test2 = "#FORM.test#">

INSERT INTO db_TBL(test1,test2)
VALUES('#test1#','#test2#')

OR
Example3:

<cfparam name="test1" default="Your default value">
<cfparam name="test2" default="Your default value">

INSERT INTO db_TBL(test1,test2)
VALUES('#test1#','#test2#')
 
Thanks for the help. I've listed some information below for clarification, as I still can't seem to get this working. I'm now looking into creating a session variable and the main problem seems to be trying to output the contents of the "test2" session variable in a textbox, which is explained below.

User enters various information on form page via textbox
-Form page
--Page name is formtest
--<input name="test">

-Action page (separate CF page)
--I simultaneously enter the textbox info into an Access database and also want to set the session variable "test2" = "test" (unless it should be performed on another page)
--I would also like to have a textbox on this page showing the contents of the session variable "test2," but I can't get it to work properly. I've tried every combination I can think of, but no luck (e.g. <CFSET session.test2="#form.test#">
 
Okay, so I've gotten the session variable established, however, I'm having an issue calling it as a value in one of my textboxes. Here are the relevant chunks of my code on my action page:

<cfset session.test2=form.test>

<input name="test3" value="#session.test2#">
//This part won't work. The session.test2 value can't be called as the initial value of a textbox for some reason. The textbox's value will be shown as the text "#session.test2#" instead of the value stored in session.test2


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top