Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. FireFox select scrolling issue

FireFox select scrolling issue

Scheduled Pinned Locked Moved Web Development
htmlgame-devhelp
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Brent Lamborn
    wrote on last edited by
    #1

    On a page we've got an HTML select defined as follows: "Half this game is ninety percent mental." - Yogi Berra If you can read thank a teacher, if you can read in English, thank a Marine.

    S 1 Reply Last reply
    0
    • B Brent Lamborn

      On a page we've got an HTML select defined as follows: "Half this game is ninety percent mental." - Yogi Berra If you can read thank a teacher, if you can read in English, thank a Marine.

      S Offline
      S Offline
      Shog9 0
      wrote on last edited by
      #2

      I'm interested to see your code... I tried doing a quick implementation to see what happens, and while i can manage to lock the scrolling in FF, it doesn't seem to be possible in IE6...

      // moves selected option in theList up by one index (if possible) (single-sel lists only)
      function moveUp()
      {
      var list = document.getElementById("theList");
      var sel = list.selectedIndex;
      if ( sel > 0 )
      {
      repositionOption(list, sel, sel-1);
      }
      }

      // moves selected option in theList down by one index (if possible) (single-sel lists only)
      function moveDown()
      {
      var list = document.getElementById("theList");
      var sel = list.selectedIndex;
      if ( sel < list.length-1 )
      {
      repositionOption(list, sel, sel+1);
      }
      }

      function repositionOption(list, sel, index)
      {
      var scroll = list.scrollTop; // save scroll pos
      var opt = list.item(sel);

      list.remove(sel);
      opt.selected = false; // mustn't be initially selected, or marking it won't scroll into view

      // deal with IE breakage
      try
      {
      list.add(opt, list.item(index));
      }
      catch(e)
      {
      // for some reason, IE uses index vs. element to insert before
      list.add(opt, index);
      }

      list.scrollTop = scroll; // restore scroll pos
      opt.selected = true; // restore selection (will scroll into view if necessary)
      }

      every night, i kneel at the foot of my bed and thank the Great Overseeing Politicians for protecting my freedoms by reducing their number, as if they were deer in a state park. -- Chris Losinger, Online Poker Players?

      B 1 Reply Last reply
      0
      • S Shog9 0

        I'm interested to see your code... I tried doing a quick implementation to see what happens, and while i can manage to lock the scrolling in FF, it doesn't seem to be possible in IE6...

        // moves selected option in theList up by one index (if possible) (single-sel lists only)
        function moveUp()
        {
        var list = document.getElementById("theList");
        var sel = list.selectedIndex;
        if ( sel > 0 )
        {
        repositionOption(list, sel, sel-1);
        }
        }

        // moves selected option in theList down by one index (if possible) (single-sel lists only)
        function moveDown()
        {
        var list = document.getElementById("theList");
        var sel = list.selectedIndex;
        if ( sel < list.length-1 )
        {
        repositionOption(list, sel, sel+1);
        }
        }

        function repositionOption(list, sel, index)
        {
        var scroll = list.scrollTop; // save scroll pos
        var opt = list.item(sel);

        list.remove(sel);
        opt.selected = false; // mustn't be initially selected, or marking it won't scroll into view

        // deal with IE breakage
        try
        {
        list.add(opt, list.item(index));
        }
        catch(e)
        {
        // for some reason, IE uses index vs. element to insert before
        list.add(opt, index);
        }

        list.scrollTop = scroll; // restore scroll pos
        opt.selected = true; // restore selection (will scroll into view if necessary)
        }

        every night, i kneel at the foot of my bed and thank the Great Overseeing Politicians for protecting my freedoms by reducing their number, as if they were deer in a state park. -- Chris Losinger, Online Poker Players?

        B Offline
        B Offline
        Brent Lamborn
        wrote on last edited by
        #3

        Ah thanks, didn't know about scrollTop. It still doesn't quite pull off the default IE 7 behaviour which continues to scroll to keep the selected index in view, but works well enough. Here is what we use:

        function orderSelect($down,$oName,$fName,$EXCLUDE) { 
        	// moves Categories, Subcategories, and xxxxxx up and down in a list
        	if(typeof($oName)!="object"){var $obj = document[$fName][$oName];} else {$obj = $oName;}
          	$sl = $obj.selectedIndex;
          	
            var scroll = $obj.scrollTop;
        
          if($obj.options[$sl].text==$EXCLUDE || $obj.options[$sl].value==$EXCLUDE){alert("This item cannot be altered.");return false}
          if ($sl != -1 && $obj.options[$sl].value > "") {
        	 $oText = $obj.options[$sl].text;
        	 $oValue = $obj.options[$sl].value;
        	 if ($obj.options[$sl].value > "" && $sl > 0 && $down == 0) {
        		if($obj.options[$sl-1].text==$EXCLUDE){alert("This item cannot be moved into that position.");return false}
        		$obj.options[$sl].text = $obj.options[$sl-1].text;
        		$obj.options[$sl].value = $obj.options[$sl-1].value;
        		$obj.options[$sl-1].text = $oText;
        		$obj.options[$sl-1].value = $oValue;
        		$obj.selectedIndex--;
        		$obj.scrollTop = scroll;
        	 } else if ($sl < $obj.length-1 && $obj.options[$sl+1].value > "" && $down == 1) {
        		if($obj.options[$sl+1].text==$EXCLUDE){alert("This item cannot be moved into that position.");return false}
        		$obj.options[$sl].text = $obj.options[$sl+1].text;
        		$obj.options[$sl].value = $obj.options[$sl+1].value;
        		$obj.options[$sl+1].text = $oText;
        		$obj.options[$sl+1].value = $oValue;
        		$obj.selectedIndex++;
        		$obj.scrollTop = scroll;
        	 }
        	 return true;
          } else {
        	 alert("Please select an item first.");
        	 return false;
          }
        }
        

        orderSelect is called in the onclick event for an image input. Thanks for the help!


        "Half this game is ninety percent mental." - Yogi Berra If you can read thank a teacher, if you can read in English, thank a Marine.

        S 1 Reply Last reply
        0
        • B Brent Lamborn

          Ah thanks, didn't know about scrollTop. It still doesn't quite pull off the default IE 7 behaviour which continues to scroll to keep the selected index in view, but works well enough. Here is what we use:

          function orderSelect($down,$oName,$fName,$EXCLUDE) { 
          	// moves Categories, Subcategories, and xxxxxx up and down in a list
          	if(typeof($oName)!="object"){var $obj = document[$fName][$oName];} else {$obj = $oName;}
            	$sl = $obj.selectedIndex;
            	
              var scroll = $obj.scrollTop;
          
            if($obj.options[$sl].text==$EXCLUDE || $obj.options[$sl].value==$EXCLUDE){alert("This item cannot be altered.");return false}
            if ($sl != -1 && $obj.options[$sl].value > "") {
          	 $oText = $obj.options[$sl].text;
          	 $oValue = $obj.options[$sl].value;
          	 if ($obj.options[$sl].value > "" && $sl > 0 && $down == 0) {
          		if($obj.options[$sl-1].text==$EXCLUDE){alert("This item cannot be moved into that position.");return false}
          		$obj.options[$sl].text = $obj.options[$sl-1].text;
          		$obj.options[$sl].value = $obj.options[$sl-1].value;
          		$obj.options[$sl-1].text = $oText;
          		$obj.options[$sl-1].value = $oValue;
          		$obj.selectedIndex--;
          		$obj.scrollTop = scroll;
          	 } else if ($sl < $obj.length-1 && $obj.options[$sl+1].value > "" && $down == 1) {
          		if($obj.options[$sl+1].text==$EXCLUDE){alert("This item cannot be moved into that position.");return false}
          		$obj.options[$sl].text = $obj.options[$sl+1].text;
          		$obj.options[$sl].value = $obj.options[$sl+1].value;
          		$obj.options[$sl+1].text = $oText;
          		$obj.options[$sl+1].value = $oValue;
          		$obj.selectedIndex++;
          		$obj.scrollTop = scroll;
          	 }
          	 return true;
            } else {
          	 alert("Please select an item first.");
          	 return false;
            }
          }
          

          orderSelect is called in the onclick event for an image input. Thanks for the help!


          "Half this game is ninety percent mental." - Yogi Berra If you can read thank a teacher, if you can read in English, thank a Marine.

          S Offline
          S Offline
          Shog9 0
          wrote on last edited by
          #4

          Ah, well that's a bit different. Try restoring the scroll position before modifying the selected index - that ought to let FF keep the selection in view. If not, then try also changing $obj.selectedIndex++ to $obj.options[$sl+1].selected = true.

          every night, i kneel at the foot of my bed and thank the Great Overseeing Politicians for protecting my freedoms by reducing their number, as if they were deer in a state park. -- Chris Losinger, Online Poker Players?

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups