Select box onclick fill a textbox

Hi all :),
I am trying to

  1. display a select box
  2. onclick (extract the value and the text from the clicked item) in the select box and fill 2 text boxes.
    Would be grateful for any pointers.
    TIA :slight_smile:

<script type=“text/javascript”>

function disp_text()
var w = document.myForm.mylist.selectedIndex;
var selected_text = document.myForm.mylist.options[w].text;
document.getElementById(box1).value = selected_text;
document.getElementById(box2).value = document.myForm.mylist.value;


<select name=“listbox” id=“mylist” size=“10” onclick="disp_text();>


You don’t seem to have any text boxes in your document. :confused:
Also, you haven’t told us what the global variables box1 and box2 contain. If you mean to match text boxes with id="box1" and id="box2", then you need to surround the ID values with quotes:

document.getElementById("box1").value = selected_text;


Thanks !
Sorry I meant text boxes with id=“box1” and id=“box2” :slight_smile:

be a way to access the selected text (not the value ) from the
<select name=“listbox” id=“mylist”> ?
I have tried all options without any success.

No, the .value property of the select reflects the value, not the text, of the selected option.

You should be able to get the text value like this,

var sel = document.getElementById("mylist");
var text = sel.options[sel.selectedIndex];

Thanks very much indeed !
I tested and finally go the below to work
document.myForm.title.value = document.myForm.listbox_url.options[document.myForm.listbox_url.selectedIndex].text