<cfelseif> not working for update

jslaught
jslaught used Ask the Experts™
on
1. i have a display form myopensrs.cfm that displays results.

2. the display form references the update form update_action.cfm

i would like to do some pre-checks of values before the submission of the form. the inital <cfif> works but the <cfelseif> is not working. It ignores the check of the form values and doesn't display the message set in the <cfelseif>. The code is below.
================
myopensrs.cfm
================


<!--- headers --->
    <cfoutput><a href="trackertabs.cfm?user_name=#url.user_name#&tab=2"></cfoutput>    
    <img src="http://127.0.0.1:8500/TicketTracking/pics/imagesCA6WFWX0.jpg" width=50 height=50 alt="go back to service tab" border="0" /></a>


<!--- Query the database for all open service requests (per user log in) --->
<cfquery name="Getmyrequests" datasource="sspsrs">
    SELECT    * 
    FROM    Issues 
    WHERE   status = 'active' and user_name = <cfqueryparam value="#url.user_name#" cfsqltype="cf_sql_varchar">
    order by ticket_num
</cfquery>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
	<head>
		<title>My Open Service Requests</title>
	</head>
	<body>
<font size=6><i><CENTER>My Open Service Requests</center></i></font>
        

<table border='0' width="100%" align='center' summary='script output'>
    <tr bgcolor="#99ccff">
        <th bgcolor="#99ccff"><font size=2><b>Service<br> Request #</b></font></th>
        <th bgcolor="#99ccff"><font size=2></strong>Request</strong></font></th>
        <th bgcolor="#99ccff"><font size=2></strong>Network</strong></font></th>
	<th bgcolor="#99ccff"><font size=2></strong>Classification<br>of Request</strong></font></th>
        <th bgcolor="#99ccff"><font size=2></strong>Assigned<br> To</strong></font></th>
        <th bgcolor="#99ccff"><font size=2></strong>Customer<br>Last Name</strong></font></th>
	<th bgcolor="#99ccff"><font size=2></strong>Customer<br>First Name</strong></font></th>
        <th bgcolor="#99ccff"><font size=2></strong>Opened<br> Date</strong></font></th>
        <th bgcolor="#99ccff"><font size=2></strong>Closed<br>Date Date</strong></font></th>
        <th bgcolor="#99ccff"><font size=2></strong>Status</strong></font></th>
        <th bgcolor="#99ccff"><font size=2></strong>Priority</strong></font></th>
        <th bgcolor="#99ccff"><font size=2></strong>Description</strong></font></th>
        <th bgcolor="#99ccff"><font size=2></strong>Comments</strong></font></th>
        <th bgcolor="#99ccff"><font size=2></strong>Update<br> Service<br> Request</strong></font></th>
    </tr>
<!--- Output a table containing each service requests.  Create dynamic
		  links to edit and delete the service.  Pass the ID
		  associated with each record in the URL of the link --->

            <cfoutput query="Getmyrequests">
			  
            <tr bgcolor="###iif(currentrow MOD 2,DE('ffffff'),DE('cccccc'))#">
            <td><font size=2>#Ticket_num#</font></td>
            <td><font size=2>#Title#</font></td>
            <td><font size=2>#Network#</font></td>
	    <td><font size=2>#Classification_of_Request#</font></td>
            <td><font size=2>#Full_name#</font></td>
            <td><font size=2>#Last_Name#</font></td>
	    <td><font size=2>#First_Name#</font></td>
            <td><font size=2>#DateFormat(Opened_Date,'mm/dd/yyyy')#</font></td>
            <td><font size=2>#DateFormat(Closed_Date,'mm/dd/yyyy')#</font></td>
            <td><font size=2>#Status#</font></td>
            <td><font size=2>#Priority#</font></td>
            <td><font size=2>#Description#</font></td>
            <td><font size=2>#Comments#</font></td>
	    <td><a href="http://127.0.0.1:8500/TicketTracking/update_sr.cfm?user_name=#url.user_name#&ticket_num=#ticket_num#">Update</a></td>
			  </tr>
			</cfoutput>
             
			  
		</table>
	</body>
</html>

==================
update_action.cfm
==================

<cfquery name="changeun" datasource="sspsrs">
    SELECT user_name
    FROM tblAdmins where Full_name = <cfqueryparam value="#form.full_name#" cfsqltype="cf_sql_varchar"> 
</cfquery>


  <cfoutput><a href="myopensrs.cfm?user_name=#url.user_name#"></cfoutput>    
    <img src="http://127.0.0.1:8500/TicketTracking/pics/returnwc.jpg" width=60 height=60 alt="go back to service tab" border="0" /></a>
<br>
<br>
<body bgcolor="#99ccff">


<cfif #form.status# is 'Resolved' and #form.closed_date# is "">
<script>
              alert("Please choose a closed date before closing this service request.");
              self.location="http://127.0.0.1:8500/TicketTracking/update_sr.cfm?<cfoutput>user_name=#url.user_name#&ticket_num=#ticket_num#</cfoutput>";
</script>

<!--- =========== having problems with this <cfelseif> here
=================--->
<cfelseif #form.status# = 'Active'>

<script>
              alert("Please change the status to "resolve" before closing this service request.");
              self.location="http://127.0.0.1:8500/TicketTracking/update_sr.cfm?<cfoutput>user_name=#url.user_name#&ticket_num=#ticket_num#</cfoutput>";
</script> 





<cfelse>

<!--- Update the record, and write the new data to the database --->
	  <cfquery datasource="sspsrs">
  		UPDATE Issues
  		SET		
				title= <cfqueryparam value="#Form.title#" cfsqltype="cf_sql_varchar">,
				network= <cfqueryparam value="#Form.Network#" cfsqltype="cf_sql_varchar">,
				Classification_of_Request= <cfqueryparam value="#Form.Classification_of_Request#" cfsqltype="cf_sql_varchar">,
				full_name= <cfqueryparam value="#Form.full_name#" cfsqltype="cf_sql_varchar"> ,
				
				user_name= <cfqueryparam value="#changeun.user_name#">,

				Last_Name= <cfqueryparam value="#Form.Last_Name#" cfsqltype="cf_sql_varchar">,
				First_Name= <cfqueryparam value="#Form.First_Name#" cfsqltype="cf_sql_varchar">,
				Opened_Date= <cfqueryparam value="#DateFormat(Form.Opened_Date, 'mm/dd/yyyy')#" cfsqltype="cf_sql_date">,
				closed_date= <cfqueryparam value="#DateFormat(Form.closed_date, 'mm/dd/yyyy')#" cfsqltype="cf_sql_date">,
				status= <cfqueryparam value="#Form.status#" cfsqltype="cf_sql_varchar">,
				priority= <cfqueryparam value="#Form.priority#" cfsqltype="cf_sql_varchar">,
				description= <cfqueryparam value="#Form.description#" cfsqltype="cf_sql_varchar">,
				comments= <cfqueryparam value="#Form.comments#" cfsqltype="cf_sql_varchar">

	WHERE ticket_num = <cfqueryparam value="#url.ticket_num#" cfsqltype="cf_sql_integer">								  
	  </cfquery>
</cfif>

	  <!--- display the tip that was entered into the database--->
		  <font size = 4 font color="#ffffff"><b>The following Service Request was updated:</b></font>	<br /> <br />  <br />  
  	  <cfoutput>
		
		<b>Service Request:</b> - #url.ticket_num# <br  /><br />
		<b>Title:</b> - #Title# <br  /><br /> 
		<b>Network:</b> - #Network# <br  /><br /> 
		<b>Classification of Request:</b> - #Classification_of_Request#  <br  /><br /> 
		<b>Assigned To:</b> - #full_name#  <br  /><br />
		<!---<b>User Name:</b> - #user_name# <br  /><br />---> 
		<b>Last Name:</b> - #Last_name# <br  /><br /> 
		<b>First Name:</b> - #First_name# <br  /><br /> 
		<b>Opened Date:</b> - #Opened_Date# <br  /><br /> 
		<b>Closed Date:</b> - #Closed_Date# <br  /><br /> 
		<b>Status:</b> - #status# <br  /><br /> 
		<b>Priority:</b> - #priority# <br  /><br /> 
		<b>Description:</b> - #description# <br  /><br /> 
		<b>Comments:</b> - #comments# <br  /><br /> 
	  </cfoutput>
	  <br /> <br /> 
	

</body>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Brijesh ChauhanStaff IT Engineer

Commented:
<cfelseif #form.status# = 'Active'> LINE 99 of code

Change to

<cfelseif #form.status# EQ 'Active'>
Brijesh ChauhanStaff IT Engineer

Commented:
OR Better for strings use COMPARE function..

<cfelseif NOT compareNoCase('#form.status#','Active')>

http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=functions-pt0_18.html

Author

Commented:
<cfelseif #form.status# = 'Active'> does not work.

<cfelseif #form.status# EQ 'Active'> does not work.

<cfelseif NOT compareNoCase('#form.status#','Active')> does not work.

<cfelseif #form.status# is 'Active'> does not work.

in each case the <cfelseif > is ignored.

any other suggestions...


Acronis in Gartner 2019 MQ for datacenter backup

It is an honor to be featured in Gartner 2019 Magic Quadrant for Datacenter Backup and Recovery Solutions. Gartner’s MQ sets a high standard and earning a place on their grid is a great affirmation that Acronis is delivering on our mission to protect all data, apps, and systems.

Top Expert 2011

Commented:
- try putting doublequote to "Active" instead of single quote
- does Active and Resolve is passed from previous page? check the case of the character if its the same or are all lowercase?

Author

Commented:
using doube quotes "Active" did not work either within the <cfelseif>. It is still being ignored.

Active and resolve are apart of a dropdown box on that form. The <cfif> is supposed to check to see if the user selected active or resolved for a status before the submit button is executed.
Top Expert 2011

Commented:
- i'm curious the value of status. do a cfdump on status in update_action.cfm to see what is the value it gets.
- and what does this line in update_action.cfm display for status: <b>Status:</b> - #status# <br  /><br />

Author

Commented:
cfdump shows that the value of  #status# is Active
Top Expert 2011
Commented:
- i think its the problem with the alert syntax itself:

alert("Please change the status to "resolve" before closing this service request.");
- take out the doublequote that wrap "resolve".
Brijesh ChauhanStaff IT Engineer

Commented:
What is your FORM ? I did a small test and everything seems to be working correctly.. here is what I tested..

<!--- === THE FORM === --->
<cfparam name="show" default="0">
<form name="testForm" action="" method="post">
	<input type="hidden" name="show" value="1">
	<select name="status">
    	<option value="resolved"> RESOLVED </option>
        <option value="Active"> ACTIVE </option>
        <option value="NONE"> NONE </option>
    </select>
    <input type="hidden" name="closed_date" value="">
    <input type="submit" name="submit" value="submit">
</form>

<!--- === ACTION === --->
<cfif show>
<cfdump var="#form#">

<cfif NOT compareNoCase('#form.status#','resolved') and form.closed_date EQ '' >
	<cfoutput> RESOLVED </cfoutput>
<cfelseif NOT compareNoCase('#form.status#','Active')>
	<cfoutput> ACTIVE </cfoutput>
<cfelse>
	<cfoutput> NONE </cfoutput>
</cfif>
</cfif>

Open in new window


CompareNoCase should compare the form value (STATUS) and 'active' irrespective of the CASE.. also what happens when you have status as 'active' which portion does it execute ?
Use this one
<cfif trim(LCase(form.status)) EQ 'resolved'>
true part module
<cfelseif trim(LCase(form.status)) EQ 'active'>
else part module
</cfif>

Thanks

There were two problems, first you need to use  IS or EQ in your CFELSEIF instead of the = equal sign.  There is no need to play with the case (change it to lower, etc) because the IS and EQ operators are case insensitive.

The second problem was the use of " quotes inside of your alert() function.  You need to change either the outer quotes or the innner quotes to single quotes (see code below).

To test if the code was getting inside the CFELSEIF statement, you should have put some type of display, that would have let you know it WAS getting inside the CFELSEIF and your problem was the javsacript error...

<cfif form.status is 'Resolved' and form.closed_date is "">
  <script>
     alert("Please choose a closed date before closing this service request.");
     self.location="http://127.0.0.1:8500/TicketTracking/update_sr.cfm?<cfoutput>user_name=#url.user_name#&ticket_num=#ticket_num#</cfoutput>";
  </script>

<cfelseif form.status is 'Active'>

   <h1>Status is Active!</h1>
   <script>
      alert("Please change the status to 'resolve' before closing this service request.");
      self.location="http://127.0.0.1:8500/TicketTracking/update_sr.cfm?<cfoutput>user_name=#url.user_name#&ticket_num=#ticket_num#</cfoutput>";
   </script> 

</cfif>

Open in new window

Author

Commented:
The below suggestion worked! It was just the extra quotes.

- i think its the problem with the alert syntax itself:

alert("Please change the status to "resolve" before closing this service request.");
- take out the doublequote that wrap "resolve".


However I have other pre-checks on the same form before the user can submit a new request succesfully making sure a value is entered/selected for required fields. Currently having trouble with the code below. The code below is being ignored when clicking submit.

[u]add new form[/u]

<tr>
<td><br>* Request Type:</b></br></td>
<td>select name="Title">
<option value="">---Select Option---</option>
<cfloop value="dropdownvalues.title_name#">#dropdownvalues.title_name#</option>
<cfloop>
</select></td>
</tr>

[u]insert new form[/u]

<cfif #form.title# eq "">
<script>
alert("You must select a Request Type!");
self.location="http://127.0.0.1:8500/TicketTracking/addnewsr.cfm?user_name=#url.user_name#;
</script>

Open in new window

Top Expert 2011

Commented:
- great that my suggestion work for you on the alert. you can replace the doublequotes for "resolve" with single quote or bold or put uppercase.

- i believe the pre-checks is a new question as the original question has been resolved. i would suggest you to open a new question on that.
- however for tips: if after the alert you want to go back to the previous page (submitting page), just use self.location="Javascript:history.go(-1)";
> The below suggestion worked! It was just the extra quotes.

No, not just the quotes.  This line's syntax is incorrect and will not work.   You had to have changed it to IS or EQ to get the statement to work.

 <cfelseif #form.status# = 'Active'>  will cause an error


This code block has a couple problems, the SELECT tag is missing a bracket and the opening <option> tag is not there...  please see code block below.

General comment - I don't think javascript after a form post is a good method to present error messages.  Javascript is often used to keep from having to process a form post (so it stops the user before the page is submitted).   If you're actually going to do the form post, don't use a js pop-up, it's really annoying to the user.   Instead, simply display the message at the top of the screen, you can even highlight the line with the error with an icon of different color if you want to.




<td>
  <select name="Title">
    <option value="">---Select Option---</option>
    <cfloop value="dropdownvalues.title_name#">
      <option>#dropdownvalues.title_name#</option>
    <cfloop>
  </select>
 </td>
</tr>

Open in new window

Author

Commented:
this was just one resolution of others on the same form i'm trying to resolve. Thanks for the help.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial