?
Solved

CF selecting items in select box

Posted on 2010-09-23
9
Medium Priority
?
269 Views
Last Modified: 2013-12-24
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.
0
Comment
Question by:Galina Besselyanova
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 
LVL 57

Expert Comment

by:HainKurt
ID: 33748358
dont put same numbers ;)

why do you have same numbers in select box?

can you give sample?
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 33748693
Is this a trivia question?

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


0
 

Author Comment

by:Galina Besselyanova
ID: 33750192
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
0
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 
LVL 57

Expert Comment

by:HainKurt
ID: 33750369
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

0
 
LVL 57

Expert Comment

by:HainKurt
ID: 33750374
a small fix

onchange="return checkOrder(this)"
-->
onchange="checkOrder(this)"
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 33751735
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";
}

0
 

Author Comment

by:Galina Besselyanova
ID: 33753967
wow. Thanks guys.
I'll definetly try it.
0
 
LVL 57

Accepted Solution

by:
HainKurt earned 2000 total points
ID: 33754301
Thanks Zvonko,

I thought

if (isSelected(sb)) sb.value=oldVal;

will not work, and thats why I added that function, then forgot to use it since setting sb.value directly was working ;)

Here is the revised version with that function...
<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;
  if (isSelected(sb)) selectOldValue(sb);
}

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 == oldVal) sb.options[i].selected="selected";
}
</SCRIPT>

<div id=divOrder>
A : <select id=sel1 onclick="setOldValue(this)" onchange="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="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="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

0
 

Author Comment

by:Galina Besselyanova
ID: 33823216
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?


 
0

Featured Post

Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

801 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