Web Analytics Made Easy -
StatCounter Combo Selection - CodingForum

Announcement

Collapse
No announcement yet.

Combo Selection

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Combo Selection

    This is my currect script:

    Code:
    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!
    Last edited by mr_ego; Jul 14, 2002, 06:37 AM.
    -mR_eGo
    _______________________
    Programming since
    3 years old.

  • #2
    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.
    Code:
    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?
    neil.c

    Comment


    • #3
      The code Neil said is fine :

      Code:
      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;
          [B]break;[/B] 
        }
      }
      thebox.colour.selectedIndex=selectThisOne;
      Just added the break; because you don't need to loop thro' if you found the color!
      Scripting | JavaScripts | PerlScripts | Python Scripts | Articles | My Journal

      Comment


      • #4
        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.
        neil.c

        Comment

        Working...
        X