View Full Version : Combo Selection
mr_ego
07-14-2002, 10:38 AM
This is my currect script:
document.main.title.value = window.opener.document.getElementById('title').innerHTML;
thebox.colour.selectedIndex = window.opener.document.getElementById('title').style.color;
yeah ... so basically i have a popup window with a select and text box in there and i need the select box to say the value of the parents' style from <div id=title>.
This script above doesnt work ... someone help!
neil.c
07-14-2002, 11:54 AM
at a guess, i'd say style.colour returns a hex colour value like '#FF0000' for red, or possibly the name of the colour eg 'red'. but selectedIndex is a number - the position of an item in a combo (SELECT) box. are you trying to get the combo to select the item 'red'? you'll have to make a script that goes through all the options and finds the one called 'red', then selects this one. eg.
var selectThisOne = 0
var colourName = window.opener.document.getElementById('title').style.color
for (i=0, i<thebox.colour.length, i++){
if (thebox.colour.options[i] = colourName){
selectThisOne=i
}
}
thebox.colour.selectedIndex=selectThisOne
ok?
premshree
07-14-2002, 04:05 PM
The code Neil said is fine :
var selectThisOne = 0;
var colourName = window.opener.document.getElementById;('title').style.color
for (i=0, i<thebox.colour.length, i++){
if (thebox.colour.options[i] = colourName){
selectThisOne=i;
break;
}
}
thebox.colour.selectedIndex=selectThisOne;
Just added the break; because you don't need to loop thro' if you found the color!
neil.c
07-14-2002, 09:07 PM
Just added the break; because you don't need to loop thro' if you found the color!
sure, anything to cut out a few extra microseconds of processing.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.