9 Replies - 909 Views - Last Post: 27 February 2014 - 08:20 PM

#1 DarenR  Icon User is offline

  • D.I.C Lover

Reputation: 497
  • View blog
  • Posts: 3,314
  • Joined: 12-January 10

only allow one choice in multiple drop down select boxes

Posted 26 February 2014 - 11:19 AM

Ok this is kind of a weird thing:

what I have:

10+ dynamically created select boxes in html that are all named the same except for a number next to them liek the following:
repairs1
repairs2
repairs3
and so on

each select box has exactly the same select options.

What the client wants is to be able to only select 1 item from a drop down and have that option disabled on all the other dropdowns

I know how to get the indexes but how do you disable a certain index from the other drop downs?

for instance
if i pick item 1 from select box 1 , I want item 1 to be disabled in all the other select boxes.

thanks again

Is This A Good Question/Topic? 0
  • +

Replies To: only allow one choice in multiple drop down select boxes

#2 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3576
  • View blog
  • Posts: 10,441
  • Joined: 08-June 10

Re: only allow one choice in multiple drop down select boxes

Posted 26 February 2014 - 12:25 PM

then set their disabled property to true.
Was This Post Helpful? 0
  • +
  • -

#3 DarenR  Icon User is offline

  • D.I.C Lover

Reputation: 497
  • View blog
  • Posts: 3,314
  • Joined: 12-January 10

Re: only allow one choice in multiple drop down select boxes

Posted 26 February 2014 - 01:13 PM

I wasnt sure if select boxes create ddynamically had that disabled property. thanks
Was This Post Helpful? 0
  • +
  • -

#4 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3576
  • View blog
  • Posts: 10,441
  • Joined: 08-June 10

Re: only allow one choice in multiple drop down select boxes

Posted 26 February 2014 - 02:44 PM

an HTML element has always the properties an HTML element can have, no matter whether dynamically created or not. programming would be very difficult otherwise. (or in other words, how else then dynamically could you create an HTML element?)
Was This Post Helpful? 0
  • +
  • -

#5 JMRKER  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 129
  • View blog
  • Posts: 837
  • Joined: 25-October 08

Re: only allow one choice in multiple drop down select boxes

Posted 26 February 2014 - 07:01 PM

Would something like this work for you?

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title> Untitled </title>
</head>
<body>
 <select id="SBox0" onclick="NewList('SBox0','SBox1')">
  <option value="1">1</option>
  <option value="2">2</option>
  <option value="3">3</option>
  <option value="4">4</option>
  <option value="5">5</option>
  <option value="6">6</option>
  <option value="7">7</option>
  <option value="8">8</option>
  <option value="9">9</option>
  <option value="10">10</option>
 </select>
 <select id="SBox1" onclick="NewList('SBox1','SBox2')"> <option value=""></option> </select> 
 <select id="SBox2" onclick="NewList('SBox2','SBox3')"> <option value=""></option> </select> 
 <select id="SBox3" onclick="NewList('SBox3','SBox4')"> <option value=""></option> </select> 
 <select id="SBox4" onclick="NewList('SBox4','SBox5')"> <option value=""></option> </select> 
 <select id="SBox5" onclick="NewList('SBox5','SBox6')"> <option value=""></option> </select> 
 <select id="SBox6" onclick="NewList('SBox6','SBox7')"> <option value=""></option> </select> 
 <select id="SBox7" onclick="NewList('SBox7','SBox8')"> <option value=""></option> </select> 
 <select id="SBox8" onclick="NewList('SBox8','SBox9')"> <option value=""></option> </select> 
 <select id="SBox9"> <option value=""></option> </select>

<script type="text/javascript">
/* This script and many more are available free online at
The Javascript Source!! http://www.javascriptsource.com
Created by: Jay M. Rumsey, OD | http://www.nova.edu/~rumsey */

function NewList(selObj,newObj) {
  var selElem = document.getElementById(selObj);
  var selIndex = selElem.selectedIndex;
  var newElem = document.getElementById(newObj);
  var tmp = '';
  newElem.options.length = 0;
  for (var i=0; i<selElem.options.length; i++) {
    tmp = selElem.options[i].value;
    if (i != selIndex) { newElem.options[newElem.options.length] = new Option(tmp,tmp); }
  }
}
</script>

</body>
</html>


Modified from: http://www.javascrip...own-list-2.html
Was This Post Helpful? 0
  • +
  • -

#6 DarenR  Icon User is offline

  • D.I.C Lover

Reputation: 497
  • View blog
  • Posts: 3,314
  • Joined: 12-January 10

Re: only allow one choice in multiple drop down select boxes

Posted 27 February 2014 - 01:57 PM

this is what i Have but it doesnt seem to be disabling the items

         function get_repair_drop_down(x) {
            for (var i = 1; i < 6; i++) {

                var selected_index = document.Form1.elements["PS_FORM/SUBJECT_PROPERTY/Repair_Type" + i].selectedIndex;
                var selects = document.getElementById('PS_FORM/SUBJECT_PROPERTY/Repair_Type' + i);

                for (var j = 0; j < selects.length; j++) {

                    if(selects[j] == x){
                        continue;
                        selects[j].options[selected_index].disabled = true;



                       }
                }
           }
     }


Was This Post Helpful? 0
  • +
  • -

#7 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3576
  • View blog
  • Posts: 10,441
  • Joined: 08-June 10

Re: only allow one choice in multiple drop down select boxes

Posted 27 February 2014 - 02:16 PM

Quote

it doesnt seem to be disabling the items

if you short-circuit the cycle before you do that, of course it will not disable anything.

although, what’s the point in disabling even the current selection?
Was This Post Helpful? 0
  • +
  • -

#8 DarenR  Icon User is offline

  • D.I.C Lover

Reputation: 497
  • View blog
  • Posts: 3,314
  • Joined: 12-January 10

Re: only allow one choice in multiple drop down select boxes

Posted 27 February 2014 - 02:19 PM

What the client wants is if i Pick something in drop down list one -- all other drop downlist selection of the same type to be disabled.
so
drop1
item x selected would be disabled in all other drop downlists

drop2
itemx.disabled
drop3
itemx.disabled
and so on
Was This Post Helpful? 0
  • +
  • -

#9 FerretHolmes  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 41
  • View blog
  • Posts: 167
  • Joined: 12-November 12

Re: only allow one choice in multiple drop down select boxes

Posted 27 February 2014 - 02:32 PM

Perhaps just use the .remove() and .add() methods?
Was This Post Helpful? 0
  • +
  • -

#10 JMRKER  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 129
  • View blog
  • Posts: 837
  • Joined: 25-October 08

Re: only allow one choice in multiple drop down select boxes

Posted 27 February 2014 - 08:20 PM

What was wrong with the post #5 solution?

By eliminating the option from each of the following select dropdown boxes
you have effectively disabled the repeat selection of the option.
How does that not fulfill your original requirements?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1