Unselect value from a listbox

wxdqz

New Member
Hi!
Does anyone know how to unselect a selected value from a listbox by using JavaScript?

Ex:
I have a textbox (<input type=text name=textbox>) and a listbox (<select name=listbox>) on a page.
When I click (select) a value in the listbox the textbox is cleared: onclick="document.myform.textbox.value='';"
That works fine...
But I want the opposite function too... i.e. when I click on the textbox, then any selected value in the listbox shall be unselected.

A guy suggested this function:

function clrList() {
var i;
for (i=0;i<document.myform.listbox.length;i++) {
document.myform.listbox.options.checked=false;
}
}

...but that doesn't seem to work...

Any suggestions?
 
Back
Top