Hi guys! I want to create a form whereby whenever a value is selected from a list of select field it's corresponding value should appear on the text field. example,if the select field has a list of file numbers,then if a certain file number is selected the corresponding file name should apppear on the text field
Before you get your hand on the script, i suggest you read the following few references: [1]getElementById() http://msdn.microsoft.com/en-us/library/ms536437(VS.85).aspx [2]getElementsBytagName() http://msdn.microsoft.com/en-us/library/ms536439(VS.85).aspx [3]selectedIndex property of SELECT element http://msdn.microsoft.com/en-us/library/ms534624(VS.85).aspx The javascript: <script type="text/javascript"> function set_text_field() { var select_box=document.getElementById("select_box"); var selectionOptionIndex=select_box.selectedIndex; var optionSet=select_box.getElementsByTagName("option"); var selectedOption=optionSet[selectionOptionIndex]; var value_to_copy=selectedOption.value; document.getElementById("text_field").value=value_to_copy; } </script> Code (javascript): the HTML: <select onchange="set_text_field()" id="select_box"> <option value="1">File 1</option> <option value="2">File 2</option> <option value="3">File 3</option> <option value="4">File 4</option> <option value="5">File 5</option> </select> <input type="text" id="text_field"> HTML: