Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

clearing drop down element

Status
Not open for further replies.

leahyj

MIS
May 5, 2004
107
US
I have tried two versions of code from this forum to clear my drop down of all data, but get an error at the bottom of my browser status bar.

First method:

<script type="text/javascript">

function State_Select()
{

ind = document.payoff_regionsearch.StateList.selectedIndex;
val = document.payoff_regionsearch.StateList.options[ind].value;

var i;

for (i = document.payoff_regionsearch.CountyList.options.length - 1; i >= 1; i--){
document.payoff_regionsearch.CountyList.options = i;
}

//rest of function State_Select


Second method:

<script type="text/javascript">

function clearList()
{ //Clears any existing elements in the selectbox
var len = document.getElementById('CountyList').options.length
for(i = 0; i < len; i++)
document.getElementById('CountyList').options[0] = null;
}


function State_Select()
{

ind = document.payoff_regionsearch.StateList.selectedIndex;
val = document.payoff_regionsearch.StateList.options[ind].value;


//call clearlist function
clearlist();

//rest of function State_Select


Thanks for your help.

I believe the <select> / dropdown is an html element, not activex control, etc.

I'm not sure how to debug either.
 
Cleaning up is done simply like this.
[tt]
function clearList()
{ //Clears any existing elements in the selectbox
document.getElementById('CountyList').options.length = 0;
}
[/tt]
 
To Tsuji:

Thanks for your reply to my issue.

I tried your suggestion, but for some reason, it didn't work?

Any other ideas?


Thanks.
 
I have not much of an idea... it should work somehow. Make sure you reference properly to the select-one element you want to clear. (I have not read the detail of all you've posted.)
 
To Diancecht:

That is part of my problem. I don't know how to retrieve the error description for javascript.

Maybe someone can help me with this.

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top