|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Needing a return value in a function
Hi,
Does anyone know if you have to return anything using a udf? Can you use it to display a onscreen message for false and do nothing for true or should you always return something? Regards ![]() |
|
#2
|
|||
|
|||
|
It's perfectly valid for a function to return nothing (also known as returning void). But definitely do one or the other, don't only return a value conditionally...either return a value all the time or don't return a value ever. The value can just be "true", "false", 0, or whatever. Or you can throw an exception if something unexpected happens and let the calling code deal with the exception however it wants to.
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian. How to Post a Question in the Forums |
|
#3
|
|||
|
|||
|
Hi Kiteless,
I've got a rather long form and I use js validation as well as server-side validation. I wanted a way of re-using validation code rather than having a very long action page that validates all of the form data. I decided to use a UDF which checks if a form field is required and displays a error message if no data has been entered or moves on to the next function call if data has been added. I was not sure if you needed to have it return any thing or just call the error message straight from the function. |
|
#4
|
|||
|
|||
|
It's really just a question of consistency. Whatever you decide to return, then stick with it. So if the function returns a string that holds a Javascript error checking script or an error message, then just have it return an empty string when no error is found (for example).
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ColdFusion Development > Needing a return value in a function |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|