How to pass a select option value and name

I have two "simple" CF pages. The first is an input form page where a user is given, among other things, the option of selecting 1 state from a select list. The second page is a processor page that verifies the data that was entered on the input page. I am trying to have the same state that the user selected on the input page, copied to the processor page so that the user can once again review, or change their selection, if necessary. I know how to do this using a database but the two pages I am working with do not need a database so I have a list of 50 option values as in:
                <option value="AK" >AK</option>
                <option value="AL" >AL</option>
in my select statement.

I thought I could use something like:
<select name="state">
              <option value="#form.state#"></option>
                <option value="AK" >AK</option>
</select>
But that doesn't display anything.

Might someone offer me some guidance?
Thanks,
Lee
lepirtleAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Andrew MaurerCommented:

<!--- First page --->
<form action="secondpage.cfm">
    <select name="selectedstate">
                  <option value="AL">AL</option>
                    <option value="AK" >AK</option>
    </select>
</form>
 
<!--- second page --->
<cfparam name="form.selectedstate" default="">
<form action="secondpage.cfm">
    <select name="state">
                  <option value="AL" <cfif form.selectedstate EQ "AL">selected</cfif> >AL</option>
                    <option value="AK"<cfif form.selectedstate EQ "AK">selected</cfif> >AK</option>
    </select>
</form>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
black0psCommented:
The following is a custom tag that makes the select field selected.

<form name="myForm" action="myAction">
<select name="state">
              <option value="#form.state#"></option>
                <option value="AK" >AK</option>
</select>
<cf_selected select="myForm.state" value="form.state">
</form>
<!--- This file is named selected.cfm in the same directory it is being called from --->
<cfparam name="Attributes.Value" default="#Attributes.Select#">
<cfif NOT IsDefined("Caller." & Attributes.Value) AND IsDefined("Attributes.Value")>
	<cfset v = Attributes.Value>
<cfelseif IsDefined("Caller." & Attributes.Value)>
	<cfset v = Evaluate("Caller." & Attributes.Value)>
</cfif>
<cfif IsDefined("v")>
	<cfoutput>
	<script language="Javascript">
	<!--
	ox = '#v#'
	if (document.#Attributes.Select#.multiple == true) ox = ox.split(",");
	// loop through options in select
	for (i=0;i<=document.#Attributes.Select#.options.length; i++) {
		// if select is multiple
		if (document.#Attributes.Select#.multiple == true) {
			for (j=0;j<ox.length;j++) {
				if ((document.#Attributes.Select#.options[i]) && (document.#Attributes.Select#.options[i].value == ox[j] || document.#Attributes.Select#.options[i].text == ox[j])) {
					document.#Attributes.Select#.options[i].selected = true;
				}
			}
		}
		else {
			if ((document.#Attributes.Select#.options[i]) && (document.#Attributes.Select#.options[i].value == ox || document.#Attributes.Select#.options[i].text == ox)) {
				document.#Attributes.Select#.options[i].selected = true;
				break;
			}
		}
	}
	//-->
	</script>
	<cfif IsDefined("Attributes.Message")>
		<input type="hidden" name="#ListLast(Attributes.Select,".")#_required" value="#Attributes.Message#">
	</cfif>
	</cfoutput>
</cfif>

Open in new window

0
lepirtleAuthor Commented:
Zadoc,
Once again, thank you very much. You solve my questions faster than I can incorporate them into my pages to test. Amazing!!
I surely appreciate this and am ashamed to admit how many hours I wasted today trying to make these things work.
0
CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Andrew MaurerCommented:
Thats cool.
But what is the advantage in doing it that way?
0
Andrew MaurerCommented:
Did you mean to accept BlackOps Post? tahahha
0
lepirtleAuthor Commented:
Zadoc,
In my haste to give you the points, I didn't notice that someone else also volunteered their solution and I accidentally gave them credit for the answer. I don't know if their solution works, and I am sorry that I have not tested it, but I am emailing the Experts-Exchange CF forum leader to explain what happened and to give the points to you.

Thank you blackOps but Zadoc gave me the solution first and I, though I haven't tried your solution, I must give the points to Zadoc.
0
Andrew MaurerCommented:
Much appreciated lepirtle!
0
ZvonkoSystems architectCommented:
Meanwhile test my approach:
//First page:
 
<form action="secondpage.cfm" method="POST" preserveData="yes" >
    <select name="selectedstate" >
       <option value="AL">AL</option>
       <option value="AK" >AK</option>
       <option value="AJ" >AJ</option>
       <option value="AM" >AM</option>
    </select>
    <input type="submit" >
</form>
 
 
//secondpage.cfm:
<form name="myForm" action="secondpage.cfm" method="POST"  >
    <select name="selectedstate" >
       <option value="AL">AL</option>
       <option value="AK" >AK</option>
       <option value="AJ" >AJ</option>
       <option value="AM" >AM</option>
    </select>
    <script>document.myForm.selectedstate.value="<cfoutput>#FORM.selectedstate#</cfoutput>";</script>
    <input type="submit" >
</form>

Open in new window

0
ZvonkoSystems architectCommented:
Oh, the preserveData was only a test. You do not need it for select (or cfselect) because it does not work.
0
Andrew MaurerCommented:
Thanks again lepirtle.
0
lepirtleAuthor Commented:
You are welcome. I very much appreciate your help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ColdFusion Language

From novice to tech pro — start learning today.