Link to home
Start Free TrialLog in
Avatar of Galina Besselyanova
Galina Besselyanova

asked on

CF selecting items in select box

Hello experts
please help.

below is my code

<cfquery name="selectid" datasource="ds">
      SELECT ID FROM TBL
</cfquery>
<cfset recnumb=#selectid.recordcount#>

<cfselect name="attyorder">
      <option  value=""  />
      <cfloop index="LoopCount" from="1" to="#recnumb#">
              <option  value="#selectid.id# - #LoopCount#">#LoopCount#</option>
      </cfloop>
</cfselect>

The recordcount can be 2, can be 10 , can be any.
What i need is to prevent user to select the same number from
the select box. Any ideas?

Thanks.
Avatar of HainKurt
HainKurt
Flag of Canada image

dont put same numbers ;)

why do you have same numbers in select box?

can you give sample?
Avatar of Zvonko
Is this a trivia question?

<cfset recnumb=#selectid.recordcount#-1>


Avatar of Galina Besselyanova
Galina Besselyanova

ASKER

the  numbers represents the order.
Here is  what i tried to achieve. Each record from the query should has a select box with numbers from 1 to number of records. User will select number which represent the order (for future use). See the attachment how it  looks (this is a very simple version).
what i need is if you select 2 for exmp in the box for one record , you can't  select 2 for any other record
Any suggestions?pls
 

output.jpg
here it is ;)
<SCRIPT TYPE="text/javascript">
function isSelected(sb){
  var sbarr = document.getElementById("divOrder").getElementsByTagName("SELECT");
  for (i=0; i<sbarr.length; i++)
  if ((sbarr[i] != sb) && (sbarr[i].value == sb.value)) return true;
  return false;
}

function checkOrder(sb){
  if (isSelected(sb)) sb.value=oldVal;
}

var oldVal;
function setOldValue(sb){
  oldVal = sb.value;
}

function selectOldValue(sb){
  for (var i = 0; i < sb.options.length; i++)
    if (sb.options[i].value == oldValue) sb.options[i].selected="selected";
}
</SCRIPT>

<div id=divOrder>
A : <select id=sel1 onclick="setOldValue(this)" onchange="return checkOrder(this)">
<option value=1 selected>1</option>
<option value=2>2</option>
<option value=3>3</option>
<option value=4>4</option>
</select><br>

B : <select id=sel2 onclick="setOldValue(this)" onchange="return checkOrder(this)">
<option value=1>1</option>
<option value=2 selected>2</option>
<option value=3>3</option>
<option value=4>4</option>
</select><br>

C : <select id=sel3 onclick="setOldValue(this)" onchange="return checkOrder(this)">
<option value=1>1</option>
<option value=2>2</option>
<option value=3 selected>3</option>
<option value=4>4</option>
</select><br>
</div>

Open in new window

a small fix

onchange="return checkOrder(this)"
-->
onchange="checkOrder(this)"
This function is never used in your solution and can be removed:

function selectOldValue(sb){
  for (var i = 0; i < sb.options.length; i++)
    if (sb.options[i].value == oldValue) sb.options[i].selected="selected";
}

wow. Thanks guys.
I'll definetly try it.
ASKER CERTIFIED SOLUTION
Avatar of HainKurt
HainKurt
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi ,
sorry it took a while to response, was away :( on vac :)
This code is working, thanks. However, if you check above image , i need to pass a person's id along with the number(from selectbox) to another form for processing.
where or how i can place this id? Look at this two pieces of code:
1. <cfquery name="selectid" datasource="ds">
      SELECT ID FROM TBL
</cfquery>
<cfset recnumb=#selectid.recordcount#>
<cfselect name="attyorder">
      <option  value=""  />
      <cfloop index="LoopCount" from="1" to="#recnumb#">
              <option  value="#selectid.id# - #LoopCount#">#LoopCount#</option>
      </cfloop>
</cfselect>
this gives me needed variable ID-Order , but doesn't restrict repetings in order.
2. <select name="attysend" onclick="setOldValue(this)" onchange="checkOrder(this)">
   <option  value=""  />
 <cfloop index="LoopCount" from="1" to="4">
        <option  value="#LoopCount#" id="#LoopCount#" >#LoopCount#</option>
     </cfloop>
 </select>

this one gives me needed restriction on select but  no ID, i tried different approaches  and nothing works.
any ideas?