我通过谷歌发现了一些我可以使用它的代码应该更正以适应我的但是当我从我的下拉菜单中选择一些东西时,没有任何反应。不知道我做错了什么。
<select name="h1" id="h1">
<?php
echo "<option value=".$rowlift['H1'].">".$rowlift['H1']."</option>";
$pris = mysql_query("SELECT * FROM priser ORDER BY id ASC");
while($rowP = mysql_fetch_assoc($pris))
echo "<option value='".$rowP['pris'].",".$rowP['id']."'>".$rowP['hojde']. "</option>";
?>
</select>
<?php
if($rowlift['p1'] != '')
echo "<input type='text' id='pris1' name='p1' value='".$rowlift['p1']."'>";
else
echo "<input type='text' id='pris1' name='p1'>"
?>
<script type="text/javascript">
var mytextbox = document.getElementById('pris1');
var mydropdown = document.getElementById('h1');
var mySplitResult = mydropdown.split(",");
mydropdown.onchange = function(){
mytextbox.value = mySplitResult[0];
}
</script>
我希望这是你正在寻找的想法......当我选择一些事情时,没有任何事情发生。
<select name="h1" id="h1">
<option value=""></option>
<option value="80,1">1000m</option>
<option value="90,2">1200m</option>
<option value="100,3">1500m</option>
<option value="110,4">2000m</option>
<option value="120,5">2250m</option>
<option value="130,6">2500m</option>
<option value="140,7">3000m</option>
<option value="150,8">3500m</option>
<option value="160,9">4000m</option>
<option value="160,10">Elev man.</option>
<option value="160,11">Elev auto</option>
<option value="0,12">HM</option>
<option value="2000,13">Tandem pass u/video</option>
<option value="2300,14">Tandem håndhold video</option>
<option value="2600,15">Tandem pass m/video</option>
<option value="0,16">Tandem master</option>
<option value="-100,17">Tandem video</option>
</select>
<td>
<input type="text" id="pris1" name="p1"> <script type="text/javascript">
var dropdownId = document.getElementById("h1");
var mytextbox = document.getElementById('pris1');
var mySplitResult = strUser .split(",");
dropdownId.onchange = function(){
mytextbox.value = mySplitResult[1] //to (not) appened
//mytextbox.innerHTML = this.value;
}
</script>
</td>
答案 0 :(得分:1)
我认为它应该是mydropdown.value.split(',');
答案 1 :(得分:0)
var dropdownId = document.getElementById("yourdropdownId");
var strUser = dropdownId .options[dropdownId .selectedIndex].value;
var mySplitResult = strUser .split(",");
将上述代码包装在onchange()
中答案 2 :(得分:0)
这应该是......:D
<select name="sel1" id="sel1" onchange ="show()" >
<option value="">Choose .....</option>
<option value="80~1">1000m</option>
<option value="90~2">1200m</option>
<option value="100~3">1500m</option>
<option value="110~4">2000m</option>
<option value="120~5">2250m</option>
<option value="130~6">2500m</option>
<option value="140~7">3000m</option>
<option value="150~8">3500m</option>
<option value="160~9">4000m</option>
<option value="160~10">Elev man.</option>
<option value="160~11">Elev auto</option>
<option value="0~12">HM</option>
<option value="2000~3">Tandem pass u/video</option>
<option value="2300~14">Tandem håndhold video</option>
<option value="2600~15">Tandem pass m/video</option>
<option value="0~16">Tandem master</option>
<option value="-100~17">Tandem video</option>
</select>
<td>
<input type="text" id="pris1" name="pris1">
<script type="text/javascript">
function show() {
var dropdownId = document.getElementById("sel1").value;
var mytextbox = document.getElementById('pris1');
var mySplitResult = dropdownId .split("~");
mytextbox.value = mySplitResult[0];
}
</script>