开发者

javascript onchange query issue

I have the following javascript at the head of my file.

<?php
echo "<script language='JavaScript'>\n";
echo "var times = new Array();\n";
echo "times[0] = 0;\n";
foreach($times as $time)
{
echo "times[". $time->DESC ."] = " . $time->FEE . ";\n";
}
echo "</script>\n";
?>

i then have a dropdown, where the options are the same $time->DESC,

i have an onchange, and i want to set another text box value to equal the PBT_FEE according to the PBT_DESC

i have

onchange="document.getElementById('Price').value = times[this.value];"

i presume that times[this.value] should call for the fee according to the matching descriptio开发者_JS百科ns, but i get no output


I just tried this playing with the w3schools example, and it works, so I'm guessing your problem is somewhere in the html elements.

<html>
<head>
<script type="text/javascript">

var times = new Array();
times[0] = 0;
times[1] = 1;
times[2] = 4;
times[3] = 7;
</script>
</head>
<body>

<select onchange="document.getElementById('finalPrice').value = times[this.value];">
  <option value="0">Volvo</option>
  <option value="1">Saab</option>
  <option value="2">Mercedes</option>
  <option value="3">Audi</option>
</select>

<input type="text" name="fname" id="finalPrice" /><br />

</body>
</html>


I think you should be getting the value of the dropdown box, instead of the times[this.value]...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜