0

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 descriptions, but i get no output

2 Answers 2

1

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>
Sign up to request clarification or add additional context in comments.

3 Comments

ok well my array indexes are strings, could that be the issue?
That should work too. As long as your array indexes match the option value fields. Each <option value="index"> should have a times["index"] = something.
got it to work, i had to add quotes into the php concatenation
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.