How can I change the content of a SELECT tag without refreshing the page?

Hi all... is it possible, by mean of JavaScript, to change the contents of a HTML combobox without needing to refresh the page?

I'm trying with select and option objects, but I don't know how can I do it..

For example, initially, a combobox has 5 elements.... after an event has occured, that combobox must contain 4 different elements...

Thanks a lot in advance
Skel
skelAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

avnerCommented:
try this :

<html>
<head>
<title>Select Box</title>
<script language="JavaScript">
<!--

function updateList(theChoice) {
var theList = document.theForm.listBox;
var theLength = document.theForm.listBox.options.length;
var theText = document.theForm.theText.value;
var theValue = document.theForm.theText.value;
var flag = 0;

if(theText != "") {
 if(theChoice == "add") {
  for(var i = 0; i < theLength; i++) {
    if(theText.match(theList.options[i].text)) {
    alert("This Option Already Exists");
flag++;
break;
    }//endIf
  }//endFor
  if(flag == 0){
  theList.options[theLength] = new Option(theText,theValue);
  alert(theText + " was added!");
  }//endIf
 }//endIf

 else if(theChoice == "remove") {
  for(var i = 0; i < theLength; i++) {
    if(theText.match(theList.options[i].text)) {
    theList.options[i] = null;
break;
    }//endIf
else {
flag++;
}//endElse
  }//endFor
  if(flag == theLength) {
  alert("This Option Does Not Exist");
  }//endIf
  else {
  alert(theText + " was removed!");
  }//endElse
 }//endElseIf
}//endIf

else {
alert("Please Enter A Name For The Option!");
}//endElse
}//endFunction

//-->
</script>
</head>
<body bgcolor="#FFFFFF">
<form name="theForm">
<input type="text" name="theText"> <b>Enter Option Name</b>
<br>
<br>
<select name="listBox">
<option value="">Option List</option>
<option value="Option 1">Option 1</option>
<option value="Option 2">Option 2</option>
<option value="Option 3">Option 3</option>
</select>
<br>
<br>
<input type="button" onClick="updateList('add')" value="Add Item">
<br>
<input type="button" onClick="updateList('remove')" value="Remove Item">
</form>
</body>
</html>

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.