Avatar of Jerome Slaughter
Jerome SlaughterFlag for United States of America

asked on 

<cfelseif> not working for update

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.

<!--- headers --->
    <cfoutput><a href="trackertabs.cfm?user_name=#url.user_name#&tab=2"></cfoutput>    
    <img src="" 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

<!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">
		<title>My Open Service Requests</title>
<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>
<!--- 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="">Update</a></td>


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

  <cfoutput><a href="myopensrs.cfm?user_name=#url.user_name#"></cfoutput>    
    <img src="" width=60 height=60 alt="go back to service tab" border="0" /></a>
<body bgcolor="#99ccff">

<cfif #form.status# is 'Resolved' and #form.closed_date# is "">
              alert("Please choose a closed date before closing this service request.");

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

              alert("Please change the status to "resolve" before closing this service request.");


<!--- Update the record, and write the new data to the database --->
	  <cfquery datasource="sspsrs">
  		UPDATE Issues
				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">								  

	  <!--- 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 />  
		<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 /> 
	  <br /> <br /> 


Open in new window

Web ServersColdFusion Language

Avatar of undefined
Last Comment
Jerome Slaughter
Avatar of Brijesh Chauhan
Brijesh Chauhan
Flag of India image

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

Change to

<cfelseif #form.status# EQ 'Active'>
OR Better for strings use COMPARE function..

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

Avatar of Jerome Slaughter


<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...

Avatar of OP_Zaharin
Flag of Malaysia image

- 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?
Avatar of Jerome Slaughter


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.
Avatar of OP_Zaharin
Flag of Malaysia image

- 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 />
Avatar of Jerome Slaughter


cfdump shows that the value of  #status# is Active
Avatar of OP_Zaharin
Flag of Malaysia image

Blurred text
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
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>
    <input type="hidden" name="closed_date" value="">
    <input type="submit" name="submit" value="submit">

<!--- === 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>
	<cfoutput> NONE </cfoutput>

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 ?
Avatar of psvineesh
Flag of India image

Use this one
<cfif trim(LCase(form.status)) EQ 'resolved'>
true part module
<cfelseif trim(LCase(form.status)) EQ 'active'>
else part module

Avatar of gdemaria
Flag of United States of America image

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 "">
     alert("Please choose a closed date before closing this service request.");

<cfelseif form.status is 'Active'>

   <h1>Status is Active!</h1>
      alert("Please change the status to 'resolve' before closing this service request.");


Open in new window

Avatar of Jerome Slaughter


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]

<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>

[u]insert new form[/u]

<cfif #form.title# eq "">
alert("You must select a Request Type!");

Open in new window

Avatar of OP_Zaharin
Flag of Malaysia image

- 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)";
Avatar of gdemaria
Flag of United States of America image

> 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.

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

Open in new window

Avatar of Jerome Slaughter


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

A web server refers to the software that helps to deliver web content that can be accessed either through the Internet or through an intranet. The primary function of a web server is to store, process and deliver web pages to clients. The communication between client and server takes place using the Hypertext Transfer Protocol (HTTP). The most common use of web servers is to host websites, but there are other uses such as gaming, data storage, running enterprise applications, handling email, FTP, etc.

Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews


IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo