I have a select list containing variables from a query
<tr>
<td>County Name:</td>
<td>
<select name="countyName" onchange="countyID.value = countyName.value">
<option>Select a County</option>
<cfloop query = "getCounties">
<option value="#countyName#" >#countyName# #countyID#</option>
</cfloop>
</select>
</td>
</tr>
How can I populate the County ID field?
<tr>
<td>County ID:</td>
<td><input type="Text" name="countyID">
</td>
</tr>
I’ve never used jQuery. Is there a way to use just JavaScript? As you can see I’ve attempted JavaScript, however I can only populate countyID with the countyName and I need it populated with countyID.
Breaking it out into a function this should work for you: Live Example
Or in short just change
this:
to this, and it should work
You need to reference your DOM elements via
document.getElementById()and not just their id aloneAnother example here