Results 1 to 3 of 3

Thread: reset select back to first option

  1. #1
    Join Date
    Aug 2007
    Location
    Harrisburg, PA
    Posts
    131
    Thanks
    6
    Thanked 9 Times in 9 Posts

    Default reset select back to first option

    Ok I have 4 select fields where they use ajax to pull in the options for the next select. If I change the first select after I already picked option for all four I want to reset the 3 under it to the first one back to the first option for each select.

    so on each select I have onchange I call a my function

    setDefault(nameOfDiv);

    and my function looks like this.

    Code:
    function setDefault(div) {
    	var priceID = document.getElementsByName('price');
    	var makeID = document.getElementsByName('make');
    	var modelID = document.getElementsByName('model');
    	
    	if(div = 'type') {
    		priceID.selectedIndex = 0;
    		makeID.selectedIndex = 0;
    		modelID.selectedIndex = 0;
    		
    		/*priceID.selected = priceID.item(1);
    		makeID.selected = makeID.item(1);
    		modelID.selected = modelID.item(1);*/
    	}
    	if(div = 'price') {
    		makeID.selected = makeID.item(1);
    		modelID.selected = modelID.item(1);
    	}
    	if(div = 'make') {
    		modelID.selected = modelID.item(1);	
            }
    }
    I don't know very much about javascript so I don't even know if I'm going about this the correct way. I hope I explained what i'm trying to do well enough. Any help is really appreciated. thanks

  2. #2
    Join Date
    Sep 2008
    Posts
    119
    Thanks
    13
    Thanked 0 Times in 0 Posts

    Default

    just repopulate all three through ajax, or have an if statement in javascript that selects all 3 pulldowns to the first option.

    you may just be looking for - document.yourformname.yourselectmenu.selectedIndex = "0";

    I'd have written "document.getElementById", but it's not DOM proper, and I always get caught for my none-dommyness.
    I feel "selectedIndex" was the missing piece to your puzzle.

    check this out for more info - http://www.mredkj.com/tutorials/tutorial002.html
    Last edited by Falkon303; 02-16-2009 at 08:12 AM.
    document.write is document.wrong

  3. #3
    Join Date
    Aug 2007
    Location
    Harrisburg, PA
    Posts
    131
    Thanks
    6
    Thanked 9 Times in 9 Posts

    Default

    thanks for the info. I ended up going with a different set up any way but thank you for the info I'm definitely going to look into the tutorial you should me for future reference. thanks again.

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
  •