View Single Post
Old 11-12-2012, 07:05 PM   PM User | #4
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,037
Thanks: 197
Thanked 2,411 Times in 2,389 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.

Last edited by Philip M; 11-12-2012 at 07:12 PM..
Philip M is offline   Reply With Quote