0 javascript coldfusion coldfusion-8
我有一个包含查询变量的选择列表
<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>
Run Code Online (Sandbox Code Playgroud)
如何填充县ID字段?
<tr>
<td>County ID:</td>
<td><input type="Text" name="countyID">
</td>
</tr>
Run Code Online (Sandbox Code Playgroud)
我从来没用过jQuery.有没有办法只使用JavaScript?正如你可以看到我已经尝试的JavaScript,但我只能填充countyID用countyName,我需要用它填充countyID.
出于好奇,你为什么要#countyName#用作你选择的价值观?如果该县(错误地或没有)有一个引号或其他可能与您的HTML混淆的东西怎么办?
你为什么不这样做:
<select name="countyName" onchange="countyID.value = this.value">
<option value="#countyID#">#countyName#</option>
</select>
Run Code Online (Sandbox Code Playgroud)