Page 2 of 4 FirstFirst 1234 LastLast
Results 11 to 20 of 32

Thread: moving options from one select list to another.

  1. #11
    Join Date
    Nov 2006
    Posts
    236
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default

    Even with your code it still throws an error in IE. because in IE none of the songs get added to sel2. It still add options to sel2 in Firefox and opera.
    Also I worry if the global vars s1 and s2 are not being used.

  2. #12
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    My code works fine in IE:

    http://home.comcast.net/~jscheuer1/s...ve_options.htm

    But you aren't moving, you're copying. So, where I have (slightly simplified over the previous version, we don't have to removeChild, browsers do it automatically):

    Code:
    function moveOption(s1, s2, opt){
    	s1 = document.getElementById(s1);
    	s2 = document.getElementById(s2);
    	opt = opt || s1.options[s1.options.selectedIndex];
    	if(opt.value){
    		s2.appendChild(opt);
    	}
    }
    A companion function to copy options could be:

    Code:
    function copyOption(s1, s2, opt){
    	s1 = document.getElementById(s1);
    	s2 = document.getElementById(s2);
    	opt = opt || s1.options[s1.options.selectedIndex];
    	if(opt.value){
    		s2.appendChild(opt.cloneNode(true));
    	}
    }
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #13
    Join Date
    Nov 2006
    Posts
    236
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default

    yeah I should just use that. I have no idea why my script wasn't working in IE.
    I'll ask more questions if I have any problems.

  4. #14
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    From what you've told me so far, this:

    http://home.comcast.net/~jscheuer1/s...te_options.htm

    might be very close to what you're looking for.

    Notes: I added error checking for selects that are out of range and to prevent duplicates. The clear function ignores the first option in the select, but doesn't have to. The functions used have also other capabilities.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #15
    Join Date
    Nov 2006
    Posts
    236
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default

    Yes, but are functions 1,2 and 3 purely optional. Can the script work with out them. I ask because I may want to add more select list or change it so select list with a particular className can send their options to sel2(sel3 in your code).

  6. #16
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    No. But that shouldn't stop you from using the code as you see fit.

    If you look over the code, it should be fairly obvious what each function does. If you have specific questions, feel free.

    In general:

    • manipOption() is the centerpiece. It does the main work of either copying or moving an option depending upon how it's invoked.


    • manipOption.noDupe() ensures that when copying or moving an option to another select, that the option's value is not already represented by another option already in the target select.


    • manipOption.inRange() determines whether or not the option to be moved exists insofar as is it a specific option element, and if not, if it is represented by an index of the from select's options, if that is a valid index for the options in that select.


    • manipOption.multiCopy() is a front end for manipOption() to get it to handle selects with the multiple attribute set visa vis allowing more than one option from a multiple select to be copied at a time, and at the same time to allow two from selects to be copied from at one time.


    • manipOption.clear() is pretty much standalone except that to conserve the global namespace it uses the main manipOption() object's namespace. What it does is optionally remove all options from a select, or only the selected one(s), depending upon how it's invoked. In it you will see:

      Code:
      for (var i = sel.options.length - 1; i > 0; --i){
      Because of that, it will always skip removing the first option. If that 0 is changed to -1, then the first option will also be removed if it qualifies for removal.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  7. #17
    Join Date
    Nov 2006
    Posts
    236
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default

    I'm getting the error manipOption is not defined.
    Line: 1
    what do you think is happening?

  8. #18
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Sounds like either a syntax error or typo, or you failed to include it in your version. What's the link to your current version?

    Please post a link to a page on your site that contains the problematic code so we can check it out.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  9. #19
    Join Date
    Nov 2006
    Posts
    236
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default

    it's off line so it's better that I give you the source.

    there are a lot of things commented out because I'm planning to do a some other things. functionally I'm wondering if it would be a good idea to add a stop function to the media player. I haven't decided what to do. but anyway here is the code. I probably made some dumb error in the HTML.

    it was so large I have to attach it.

  10. #20
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    there are a lot of things commented out
    I'll say. It's unwise to use HTML comment tags (<!-- or -->) inside a script tag. They can be used, but their logic and significance is different than when used in normal HTML. Their main reason inside a script tag though is to hide the script code from older browsers. This is no longer needed, and in the future may cause the script code to be skipped. So all comments within a script block should be javascript comments (// for 'from here to the end of the line' or /* */ for 'ignore what's between').

    That said, simply removing:

    Code:
     -->
    from line #151 seems to satisfy IE, while Firefox doesn't have a problem with it either way.

    Once you do that, both browsers recognize the 'missing' function. But you still have a problem.

    You originally asked to do this using document.getElementById(), but there are no elements with the id of sel1, sel2, or sel3. There are elements with those names. So just add here (and similar for the other two):

    Code:
    <div id="slider">	
    			<select name="sel1" id="sel1" size="13" multiple="multiple" oncha . . .
    Back in business!
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •