I'm trying to use echo $this->Html->script('dynamic_emails'); at the very beginning of the View file (ctp) to load some JavaScript, but it is currently not working. It does work if I explicitly put in place <script type="text/javascript" src="/mysite/js/dynamic_emails.js"></script> at the end of the View file.
Here is the code. I'm suspecting that function is not declared properly.. Any ideas?
dynamic_emails.js:
var mytextbox = document.getElementById('mytext');
var mydropdown = document.getElementById('dropdown');
mydropdown.onchange = function(){
mytextbox.value = 'some text';
}
getElementById()before the id is rendered, it's not going to find it. Try putting theecho $this->Html->script()script line at the bottom of the layout (not view) just to see if it works that way. Or even at the bottom of the view should work. (though ideally this should be going into some kind of "onload" event)