Replace variable value instead of adding to value string?

Posted on 2007-08-08
Last Modified: 2013-12-24
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>

Question by:Upekrithen
    LVL 14

    Accepted Solution

    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

    Author Comment

    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.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
    This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
    In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
    In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…

    734 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now