While working with some ajax stuff this morning I can across an interesting issue. I have a dynamic form where fields could or could not be defined based on user action. So the function that processed the form was nimble in the fact that it could account for missing fields. Well, it was supposed to be. I kept getting an error message alert that said a field did not exist. I found this strange since the try/catch should have prevented the alert. Here is a strip down of the code I was using:

view plain print about
1<script language="javascript">    
2    try {
3        t = ColdFusion.getElementValue('user_eml');
4    } catch (err){
5        t = '';
6    }
7</script>

Since the form field with an id of "user_eml" did not exist ColdFusion.getElementValue threw an alert that the field did not exist. The try/catch did nothing to suppress the alert. I ended up changing the code to use getElementById and the try/catch worked as expected.

Till next time,

--Dave