Issue with javascript and form elements
629790Sep 9 2010 — edited Sep 13 2010I apologize if this has been answered somewhere else, but I'm not even sure how to start searching.
I'm having an issue with JavaScript and a simple enable/disable script for form elements. What I'm trying to do is enable or disable a form element based on values in another form element. I've placed the script in the HTML Header of the page.
I've been able to get this to work successfully when I explicitly name the form element in my JavaScript. For example:
<script type="text/javascript">
function activateForm(){
var trigger=document.getElementById('P2_SEGMENT').value;
if (trigger=='Lab') {
document.getElementById('P2_NAME').disabled=false;
}
else {
document.getElementById('P2_NAME').disabled=true;
}
}
window.onload = activateForm;
</script>
This works just fine. When the page loads, it checks the value for the currently selected record, and enables/disables appropriately. I also have an 'onChange' in the P2_SEGMENT form element.
However, when I try to pass the form element name (i.e. 'P2_SEGMENT') into the function as a variable, the whole thing stops working. For example:
<script type="text/javascript">
function activateForm(element){
var trigger=document.getElementById(element).value;
if (trigger=='Lab') {
document.getElementById('P2_LAB').disabled=false;
}
else {
document.getElementById('P2_LAB').disabled=true;
}
}
window.onload = activateForm('P2_SEGMENT');
</script>
Have I made a mistake in my JavaScript? I don't think so, because if I test it with a simple 'alert(element);', it shows P2_SEGMENT in the popup box. So the variable value is being passed through...
Or is this an issue with APEX?
Thanks!