|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
IsDefined Problems...
Hello, Novice Proggrammer here. I have a problem with CF function IsDefined. Here is my code:
<cfif IsDefined(#URL.no#)> <cfset no = #URL.no#></cfif> <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <cfswitch expression="no"> <cfcase value="1"> You chose one. </cfcase> <cfcase value="2"> You chose two. </cfcase> <cfcase value="3"> You chose three. </cfcase> <cfdefaultcase> <p><a href="no.cfm?no=1">1</a></p> <p><a href="no.cfm?no=2">2</a> </p> <p><a href="no.cfm?no=3">3</a></p> <p><a href="no.cfm?no=4">4</a></p> </cfdefaultcase> </cfswitch> The logic behind the code is that all of this code is in one file. The idea is that when you first go to the page, it will present 1, 2, 3, 4 links to click on. Then it will take you back to the same page and give you a specific response, based on the clicked link. This is made in CFCASE statements. The promblem is this. When you first go to the page. URL.no will be undifined. It will err out. Element NO is undefined in URL. Ofcourse it isnt defined. Its supposed to go straight to defaultcase statement. The logic is, if its defined then pass it on to another var that my application can use. I know that Im not doing this right. Ben Forta and his 50$ WACK book isnt much help either. Could one of you guys tell me how to right this wrong. Or point me in the right direction on where I could read more about CFIF statements and this IsDefined function? I have been playing with this language for almost two years and love it to death. Its little stupid errs like this that make me lose my faith in Macromedia. Thanks in advanced with all your help! |
|
#2
|
|||
|
|||
|
I'll help here, but a couple of things first. To start with, when you are asking for help, please post the actual error message as the sticky for the CF forum states. Second, while I know it can be frustrating to deal with errors, know that in 99.9% of cases the problem is your fault, not Macromedia's. So saying things like "this makes me lose faith in Macromedia" indicates a rather arrogant point of view.
Now, isDefined takes a string, not a variable. Try this: <cfif IsDefined('URL.no')> <cfset no = URL.no> <cfelse> <cfset no = ""> </cfif> Also, the switch expression is evaluated, so I think what you really mean is: <cfswitch expression="#no#"> Or better yet, don't rely on this sort of indirect behavior (not setting anything and expecting the default case to run). Also, you don't need to copy the URL variable over to "no". You can just do something like this: <cfparam name="url.no" default=""> <cfswitch expression="#url.no#"> <cfcase value="1"> You chose one. </cfcase> <cfcase value="2"> You chose two. </cfcase> <cfcase value="3"> You chose three. </cfcase> <cfcase value=""> <p><a href="no.cfm?no=1">1</a></p> <p><a href="no.cfm?no=2">2</a> </p> <p><a href="no.cfm?no=3">3</a></p> <p><a href="no.cfm?no=4">4</a></p> </cfcase> </cfswitch> Hope that helps.
__________________
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 Last edited by kiteless : January 26th, 2005 at 06:09 PM. |
|
#3
|
|||
|
|||
|
Thanks
Thank you for taking the time to reply to my thread and your code. Now do you happen to know where I may read more about the IsDefined function? Im looking for commentary or just plain theory. I seem to not apply this function correctly, when I use it.
![]() |
|
#4
|
|||
|
|||
|
There are stickies at the top of the CF forum with links to resources and documentation...they're supposed to be the first thing you read when you come to a new forum!
![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ColdFusion Development > IsDefined Problems... |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|