...

View Full Version : Select all drop down function?



theflyingminstr
12-25-2010, 08:09 PM
Hi, is there a way, when one select is clicked, all change to the value of the one that was chosen? (ie: "b" is clicked and all change to b.)


<select>
<option>a</option>
<option>b</option>
<option>c</option>
</select>
<br>

<select>
<option>a</option>
<option>b</option>
<option>c</option>
</select>
<br>

<select>
<option>a</option>
<option>b</option>
<option>c</option>
</select>

Thanks

DJCMBear
12-25-2010, 08:39 PM
Try this out.



<!DOCTPYE html>
<html>
<head>
<title>Untitled Document</title>
<script type="text/javascript">
(function($){
$.selectAll = function(o,i) {
var j,
c = document.getElementById(o),
s = (c !== undefined)?c.getElementsByTagName('select'):false;
if(s) {
for(j=0;j<s.length;j++) {
s[j].options[i].selected = true;
}
}
};
})(window);
</script>
</head>
<body>
<div id="selectBoxes">
<select onchange="selectAll('selectBoxes',this.selectedIndex);">
<option>a</option>
<option>b</option>
<option>c</option>
</select>
<br>
<select onchange="selectAll('selectBoxes',this.selectedIndex);">
<option>a</option>
<option>b</option>
<option>c</option>
</select>
<br>
<select onchange="selectAll('selectBoxes',this.selectedIndex);">
<option>a</option>
<option>b</option>
<option>c</option>
</select>
</div>
</body>
</html>

theflyingminstr
12-25-2010, 08:47 PM
God bless you! Thanks

DJCMBear
12-25-2010, 08:49 PM
This one is more easier as you don't need a wrapping div.



<!DOCTPYE html>
<html>
<head>
<title>Untitled Document</title>
<script type="text/javascript">
(function($){
$.selectAll = function(o,i) {
var p,k,j,s = document.getElementsByTagName('select');
if(s) {
for(j=0;j<s.length;j++) {
p = s[j].className.split(' ');
for(k=0;k<p.length;k++) {
if(p[k] == o) {
s[j].options[i].selected = true;
}
}
}
}
};
})(window);
</script>
</head>
<body>
<select class="multiSwitch" onchange="selectAll('multiSwitch',this.selectedIndex);">
<option>a</option>
<option>b</option>
<option>c</option>
</select>
<br>
<select class="multiSwitch" onchange="selectAll('multiSwitch',this.selectedIndex);">
<option>a</option>
<option>b</option>
<option>c</option>
</select>
<br>
<select class="multiSwitch" onchange="selectAll('multiSwitch',this.selectedIndex);">
<option>a</option>
<option>b</option>
<option>c</option>
</select>
</body>
</html>

Philip M
12-25-2010, 08:56 PM
Your select options do not have a a value (in IE). Here is how you can change the option text, although why you would wish to do so is unclear to me.


<select id = "sel1" onchange = "go()">
<option>a</option>
<option>b</option>
<option>c</option>
</select>

<select id = "sel2">
<option>a</option>
<option>b</option>
<option>c</option>
</select>

<script type = "text/javascript">
function go() {
var si1= document.getElementById("sel1"). selectedIndex;
var txt1 = document.getElementById("sel1").options[si1].text;
var len = document.getElementById("sel2").length;
for (var i = 0; i<document.getElementById("sel2").length; i++){
document.getElementById("sel2").options[i].text = txt1;
}
}

</script>


"When you've got a mountain to climb, you may as well throw everything into the kitchen sink straight away." - Football commentator

theflyingminstr
12-25-2010, 09:11 PM
Oh cool, thanks!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum