I have the following code that works as shown here: http://jsfiddle.net/rBd53/12/
HTML/JS code in one file:
<script type="text/javascript">
var textBlocks = new Array(
'Select from the list to change this box',
'Text block two',
'Text block three');
function changeText(form) {
var ind = form.qwer.selectedIndex;
document.getElementById("display").innerHTML=textBlocks[ind];
}
</script>
<form>
<select name="qwer" onChange="changeText(this.form);">
<option value="0">Select</option>
<option value="1">One</option>
<option value="2">Two</option>
</select>
<br>
<div id="display">Select from the list to change this box</div>
</form>
How do I change this code to make it work properly with CakePHP 1.3? I have created a test_js.js file under app/webroot/js and put the <script>...</script> portion in there. I also have echo $scripts_for_layout; in app/views/layouts/default.ctp in the <head>.
I'm guessing stuff in my element (.ctp) file is incorrect. The dropdown menu and text below appear, but the text is not dynamically changed according to the option selected. I did the following.
<?php echo $this->Html->script('test_js', array('inline'=>false)); ?>
<form>
<select name="qwer" onChange="changeText(this.form);">
<option value="0">Select</option>
<option value="1">One</option>
<option value="2">Two</option>
</select>
<br>
<div id="display">Select from the list to change this box</div>
</form>