Assuming that you mean Javascript (a totally different language to Java in spite of the confusingly similar names):-
Code:
<select id = "counties" onchange = "showvalue()">
<option value = "0"> Chose a county</option>
<option value = "46">Wake</option>
<option value = "75">Franklin</option>
</select>
<br><br>
<input type = "text" id = "County_Cost">
<script type = "text/javascript">
function showvalue() {
document.getElementById("County_Cost").value = ""; // reset the field
var val = document.getElementById("counties").value;
if (val != 0) {
document.getElementById("County_Cost").value = val;
}
}
</script>
Change the County_Cost field to hidden after testing.
Riku's code uses jQuery. You did not specify that, and in any case it is silly to download the large overhead of a Javascript framework to accomplish something so simple.
The value of a select list is simply obtained with
var val = document.getElementById("counties").value;
No need for any reference to selectedIndex.
Quizmaster: Which surname was shared by a historical outlaw called "Butch" and a fictional cowboy called "Hopalong"?
Contestant: Lesbian.