Open Source & Stuff  
  |     Main Site     |      Forum     |     Contact     |
Java script :  forum.Salix.gr forum.Salix.gr
Little scripts that might be helpful. It's more like a repository of commonly used functions. Have something you want to share? post it here!! 
Goto Thread: PreviousNext
Goto: Forum ListMessage ListNew TopicSearchLog In
messageClear select box options
Posted by: panos (IP Logged)
Date: June 23, 2006 03:54AM

To clear all options from a select box you can use the next function.
Where select_id is the id of the select tag you want to clear.

function clearStatesOptions() {
	var oSelect = document.getElementById('select_id');
	for( i=oStates.options.length-1; i>=0; i--) {
		oSelect.remove(i);
	}
}

OR

function clearStatesOptions() {
	var oSelect = document.getElementById('select_id');
	while( oStates.options.length>0) {
		oSelect.remove(0);
	}
}



Edited 2 time(s). Last edit at 12/12/2006 07:48AM by panos.

messageRe: Clear <select> options
Posted by: panos (IP Logged)
Date: December 12, 2006 07:15AM

Finaly found the safest way to do it (with out crashing IE)

function clearStatesOptions() {
	var oSelect = document.getElementById('select_id');
	for( i=oStates.options.length-1; i>=0; i--) {
		oSelect.options[i]=null;
	}
}



Sorry, only registered users may post in this forum.

All Rights Reserved 2006 Salix.gr  |  Design by Ades Design |  Hosting by e-emporio |  forum.Salix.gr powered by Phorum