• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 181
  • Last Modified:

Replace variable value instead of adding to value string?

I have a form that sets a variable from the select and when submitted, outputs the variable value so I can see what it is.  Problem is that every time the select list is chosen, it doesn't REPLACE the variable value, it just ADDS it to the list!  

Example: If I select 1, (submits), I get result of "1".  Then select 8, (submits),  and I get "1,8".  Then 14, (submits) then I get "1,8,14 " as the result.  I WANT to get "1", then "8", then "14" so that every time I select, it REPLACES the value instead of adding to the string.

How do I make it replace the value?  Essential code follows: (rsUnits result set has values 1-35)

<cfparam name="Form.UnitSelected" default="00">

<cfif isdefined ("Form.UnitSelected")>
<cfset UnitSelected ="#Form.UnitSelected#">

Variable UnitSelected: <cfoutput>#Variable.UnitSelected#</cfoutput>

<form method="post" action="Unit.cfm">
<input type="hidden" name="UnitSelected" value="<cfoutput>#Form.UnitSelected#</cfoutput>" />      
<select name="UnitSelected" onchange="this.form.submit();">
      <option value="">ALL</option>
      <cfoutput query="rsUnits">
      <option value="#rsUnits.UnitID#"<cfif #rsUnits.UnitID# EQ #Form.UnitSelected#>selected="selected"</cfif>>#rsUnits.UnitID#</option>

1 Solution
Scott BennettManager TechnologyCommented:
Just take out the hidden field
<input type="hidden" name="UnitSelected" value="<cfoutput>#Form.UnitSelected#</cfoutput>" />      
or give it a new name that is different than the select box. When you have to fields named the same they will show up as a list in you form scope
UpekrithenAuthor Commented:
Right ON!  What a minor change with enormous effect.  Thanks a bunch!  I've been beating my head against the wall trying four million things to find that oh-so-close but elusive (and simple) solution.  Danka.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now