2

I've recently had to take over a badly-coded coldfusion form that I am trying to put in place some band-aid fixes until my team gets around to rewriting the entire thing. The form is embedded in a ModX site, and I'm having trouble getting the window to scroll to the response that is generated by the coldfusion form once the form is submitted. Currently, the screen just submits, and you have to scroll up to see the form response.

I've tested out a few things with calling Javascript, but it doesn't seem to work.

Here's the code I've tried that doesn't seem to work - am I on the right track? or should I be going about this in a different manner?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Transportation Request</title>
<link rel="stylesheet" href="//myurl/sfusd-styles-complete.css" />
<script type="text/javascript" src="scripts/util-functions.js"></script>
<script type="text/javascript" src="scripts/util.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/prototype/1.6.0.3/prototype.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/scriptaculous.js"></script>
<script type="text/javascript" src="scripts/clear-default-text.js"></script>
<script language="JavaScript" type="text/javascript"> 
function getCheckedValue(radioObj) {
    if(!radioObj)
        return "";
    var radioLength = radioObj.length;
    if(radioLength == undefined)
        if(radioObj.checked)
            return radioObj.value;
        else
            return "";
    for(var i = 0; i < radioLength; i++) {
        if(radioObj[i].checked) {
            return radioObj[i].value;
        }
    }
    return "";
}


function checkPurpose(form_object, input_object, object_value) { 
    if (document.bus_enroll_form.busPurpose.value == 'After School Program' && (document.bus_enroll_form.ap_name.value == '' | document.bus_enroll_form.ap_address.value == '')) { 
        return (false); 
    } else {
        return (true); 
    } 
}

function checkBusroutes() { 
    if (getCheckedValue(document.forms['bus_enroll_form'].elements['RouteIdAM']) == "" && getCheckedValue(document.forms['bus_enroll_form'].elements['RouteIdPM']) == "") { 
        return (false);     
    } else {
        return (true); 
    } 
}   

function showRoutes() {
    var schnum = $F('SchNum'); // end form variables 
    var url = 'routelist.cfm'; 
    var pars = 'SchNum=' 
                + schnum 
                + '&rnd=' + Math.random()*99999; 
            var myAjax = new Ajax.Request(
            url, 
            { 
                method: 'post',
                postBody: pars,
                onComplete: listrouteam }); } 

function listrouteam(originalRequest){
    $('RouteList').innerHTML = originalRequest.responseText; 
    var doc = document.bus_enroll_form; doc.School.value = ''; 
        doc.routeId.value = ''; 
        doc.StopID.value = ''; 
        doc.time.value = ''; 
        doc.dir.value = ''; 
    } 

function showRoutespm() {
    var schnum = $F('SchNum'); // end form variables 
    var url = 'routelistpm.cfm'; 
    var pars = 'SchNum=' 
                + schnum 
                + '&rnd=' + Math.random()*99999; 
            var myAjax = new Ajax.Request(
            url, 
            { 
                method: 'post',
                postBody: pars,
                onComplete: listroutepm }); } 

function listroutepm(originalRequest){
    document.getElementById('RouteListTitlePM').style.visibility='visible';
    $('RouteListPM').innerHTML = originalRequest.responseText; 
    var doc = document.bus_enroll_form; doc.School.value = ''; 
        doc.routeId.value = ''; 
        doc.StopID.value = ''; 
        doc.time.value = ''; 
        doc.dir.value = ''; 

    }   

function goToAnchor() {
location.href = "index.cfm#myAnchor";

}

</script>
</head>

<body style="width: 660px; background-color: #FFFFFF;  padding-right: 0px;" onload="showRoutes();showRoutespm();<cfif (IsDefined('Form.Action') AND Form.Action EQ "RequestBus")>window.scrollTo(0,0);</cfif>" >
<a name="myAnchor"></a>
<cfif (IsDefined('Form.Action') AND Form.Action EQ "RequestBus")>
<script type='text/javascript'>
//setTimeout("parent.scrollTo(0,0)",500);
setTimeout("goToAnchor()",1000);
</script>

<cfparam name="st_first_name" default="sdfasdfasdf"> 
<cfparam name="st_last_name" default="sdfasdfasdfsdaf"> 
<cfparam name="FORM.ROUTEIDAM" default="0,0,0"> 
<cfparam name="FORM.ROUTEIDPM" default="0,0,0"> 
<cfparam name="ROUTEINFOAM" default=""> 
<cfparam name="ROUTEINFOPM" default=""> 
<cfparam name="grade" default="00000">
<cfif grade eq "K">
<cfset grade2 = "K">
<cfset grade3 = "01">
<cfelse>
<cfset grade2 = NumberFormat(Grade - 1, "00")>
<cfif grade2 eq 00>
<cfset grade2 = "K">
</cfif>
<cfset grade3 = NumberFormat(Grade + 1, "00")>
</cfif>
<cfparam name="birth_month" default="1"> 
<cfparam name="birth_day" default="1">
<cfparam name="birth_year" default="1990"> 

<cfquery name="getStudent" datasource="TransportationGIS"> 
SELECT STUDENTNO, FIRSTNAME, LASTNAME, isnull(middlename,'') as middlename , SUFFIXNAME = '', BIRTHDATE, SCHNO, GRADE

   FROM rpa_ud_tblssms
WHERE   UPPER(RTRIM(FIRSTNAME)) = <cfqueryparam cfsqltype="cf_sql_varchar" value="#UCASE(TRIM(form.st_first_name))#" maxlength="15"> and 
        UPPER(RTRIM(LASTNAME)) =  <cfqueryparam cfsqltype="cf_sql_varchar" value="#UCASE(TRIM(form.st_last_name))#" maxlength="25"> and 
        BirthDate= <cfqueryparam cfsqltype="cf_sql_varchar" value="#TRIM(form.birth_month)#/#TRIM(form.birth_day)#/#TRIM(form.birth_year)#" maxlength="13">
</cfquery>

 <cfif getStudent.recordcount eq 0 or getStudent.recordcount gt 1>
<script type = 'text/javascript'>
}
function scrollWin() {
window.scrollTo(0, 0);
 }
</script>
<cfhttp method="Get"
        url="http://myurl/response_error.html" result="error_msg">
    <cfoutput><p><font color ="red">#error_msg.FileContent#</font></p></cfoutput>
<cfif LEN(RouteIdAM) gt 0> <cfset routeinfoam = listToArray (UCASE(TRIM(form.RouteIdAM)), ",")></cfif>
<cfif LEN(RouteIdPM) gt 0><cfset routeinfopm = listToArray (UCASE(TRIM(form.RouteIdPM)), ",")></cfif>
<cfif getStudent.recordcount eq 0>
<cfset reason = "No match found.">
<cfelse>
<cfset reason = "More than 1 match found.">
</cfif>

        <cfquery name="sendBusRequest" datasource="Transportation"> 
                INSERT INTO BusRequest_Unknown
                       ([FirstName]
                       ,[LastName]
                       ,[MiddleName]
                       ,[BirthDate]
                       ,[Schno]
                       ,[Grade]
                       ,[ParentEmail]
                       ,[BusSchNoAM]
                       ,[BusRouteAM]
                       ,[BusStopAM]
                       ,[BusSchNoPM]
                       ,[BusRoutePM]
                       ,[BusStopPM]
                       ,[BusPurposePM]
                       ,[AfterSchPrgmName]
                       ,[AfterSchPrgmAddress]
                       ,[CreatedOn]
                       ,[Reason]
                       ,[EnteredBy])
                 VALUES
                       (<cfqueryparam cfsqltype="cf_sql_varchar" value="#UCASE(TRIM(form.st_first_name))#" maxlength="15">
                       ,<cfqueryparam cfsqltype="cf_sql_varchar" value="#UCASE(TRIM(form.st_last_name))#" maxlength="25">
                       ,<cfqueryparam cfsqltype="cf_sql_varchar" value="#UCASE(TRIM(form.st_middle_name))#" maxlength="20">
                       ,<cfqueryparam cfsqltype="cf_sql_varchar" value="#TRIM(form.birth_month)#/#TRIM(form.birth_day)#/#TRIM(form.birth_year)#" maxlength="13">
                       ,<cfqueryparam cfsqltype="cf_sql_varchar" value="#UCASE(TRIM(form.SchNum))#" maxlength="5">
                       ,<cfqueryparam cfsqltype="cf_sql_varchar" value="#UCASE(TRIM(form.Grade))#" maxlength="2">
                       ,<cfqueryparam cfsqltype="cf_sql_varchar" value="#UCASE(TRIM(form.pg_email))#" maxlength="50">
                       ,<cfqueryparam cfsqltype="cf_sql_varchar" value="#UCASE(TRIM(form.SchNum))#" maxlength="5">
                       ,<cfqueryparam cfsqltype="cf_sql_varchar" value="#UCASE(TRIM(routeinfoam[1]))#" maxlength="7">
                       ,<cfqueryparam cfsqltype="cf_sql_varchar" value="#UCASE(TRIM(routeinfoam[3]))#" maxlength="5">
                       ,<cfqueryparam cfsqltype="cf_sql_varchar" value="#UCASE(TRIM(form.SchNum))#" maxlength="5">
                       ,<cfqueryparam cfsqltype="cf_sql_varchar" value="#UCASE(TRIM(routeinfopm[1]))#" maxlength="7">
                       ,<cfqueryparam cfsqltype="cf_sql_varchar" value="#UCASE(TRIM(routeinfopm[3]))#" maxlength="5">
                       ,<cfqueryparam cfsqltype="cf_sql_varchar" value="#UCASE(TRIM(form.BusPurpose))#" maxlength="20">
                       ,<cfqueryparam cfsqltype="cf_sql_varchar" value="#UCASE(TRIM(form.ap_name))#" maxlength="50">
                       ,<cfqueryparam cfsqltype="cf_sql_varchar" value="#UCASE(TRIM(form.ap_address))#" maxlength="100">
                       ,getDate()
                       ,<cfqueryparam cfsqltype="cf_sql_varchar" value="#Reason#" maxlength="50">
                       ,<cfqueryparam cfsqltype="cf_sql_varchar" value="PARENT" maxlength="50">)
         </cfquery>     


<cfelseif getStudent.recordcount eq 1>
    <cfquery name="getBusRequest" datasource="Transportation"> 
            SELECT STUDENTNO
            FROM BusRequest
            WHERE STUDENTNO = '#getStudent.StudentNo#' and [CreatedOn] > '5/30/2015 12:00:00 AM'
    </cfquery>
<cfif LEN(RouteIdAM) gt 0> <cfset routeinfoam = listToArray (UCASE(TRIM(form.RouteIdAM)), ",")></cfif>
<cfif LEN(RouteIdPM) gt 0><cfset routeinfopm = listToArray (UCASE(TRIM(form.RouteIdPM)), ",")></cfif>

                 <cfquery name="sendBusRequest" datasource="Transportation"> 
                INSERT INTO BusRequest
                       ([StudentNo]
                       ,[FirstName]
                       ,[LastName]
                       ,[MiddleName]
                       ,[SuffixName]
                       ,[BirthDate]
                       ,[Schno]
                       ,[Grade]
                       ,[ParentEmail]
                       ,[BusSchNoAM]
                       ,[BusRouteAM]
                       ,[BusStopAM]
                       ,[BusSchNoPM]
                       ,[BusRoutePM]
                       ,[BusStopPM]
                       ,[BusPurposePM]
                       ,[AfterSchPrgmName]
                       ,[AfterSchPrgmAddress]
                       ,[Comments]
                       ,[CreatedOn])
                 VALUES
                       (<cfqueryparam cfsqltype="cf_sql_varchar" value="#UCASE(TRIM(getStudent.StudentNO))#" maxlength="20">
                       ,<cfqueryparam cfsqltype="cf_sql_varchar" value="#UCASE(TRIM(form.st_first_name))#" maxlength="15">
                       ,<cfqueryparam cfsqltype="cf_sql_varchar" value="#UCASE(TRIM(form.st_last_name))#" maxlength="25">
                       ,<cfqueryparam cfsqltype="cf_sql_varchar" value="#UCASE(TRIM(getStudent.middlename))#" maxlength="20">
                       ,<cfqueryparam cfsqltype="cf_sql_varchar" value="#UCASE(TRIM(getStudent.suffixname))#" maxlength="10">
                       ,<cfqueryparam cfsqltype="cf_sql_varchar" value="#UCASE(TRIM(getStudent.Birthdate))#" >
                       ,<cfqueryparam cfsqltype="cf_sql_varchar" value="#UCASE(TRIM(getStudent.SchNo))#" maxlength="5">
                       ,<cfqueryparam cfsqltype="cf_sql_varchar" value="#UCASE(TRIM(getStudent.Grade))#" maxlength="2">
                       ,<cfqueryparam cfsqltype="cf_sql_varchar" value="#UCASE(TRIM(form.pg_email))#" maxlength="50">
                       ,<cfqueryparam cfsqltype="cf_sql_varchar" value="#UCASE(TRIM(getStudent.SchNo))#" maxlength="5">
                       ,<cfqueryparam cfsqltype="cf_sql_varchar" value="#UCASE(TRIM(routeinfoam[1]))#" maxlength="7">
                       ,<cfqueryparam cfsqltype="cf_sql_varchar" value="#UCASE(TRIM(routeinfoam[3]))#" maxlength="5">
                       ,<cfqueryparam cfsqltype="cf_sql_varchar" value="#UCASE(TRIM(getStudent.SchNo))#" maxlength="5">
                       ,<cfqueryparam cfsqltype="cf_sql_varchar" value="#UCASE(TRIM(routeinfopm[1]))#" maxlength="7">
                       ,<cfqueryparam cfsqltype="cf_sql_varchar" value="#UCASE(TRIM(routeinfopm[3]))#" maxlength="5">
                       ,<cfqueryparam cfsqltype="cf_sql_varchar" value="#UCASE(TRIM(form.BusPurpose))#" maxlength="20">
                       ,<cfqueryparam cfsqltype="cf_sql_varchar" value="#UCASE(TRIM(form.ap_name))#" maxlength="50">
                       ,<cfqueryparam cfsqltype="cf_sql_varchar" value="#UCASE(TRIM(form.ap_address))#" maxlength="100">
                       ,<cfqueryparam cfsqltype="cf_sql_varchar" value="INPUTTED BY PARENT" maxlength="100">
                       ,getDate())
         </cfquery>
    <cfif getBusRequest.recordcount eq 0>   
<script type="text/javascript">
}
function scrollWin() {
window.scrollTo(0, 0);
 }
</script>
                <cfhttp method="Get"
            url="http://myurl/response_success.html" result="success_msg">
        <cfoutput>
<p><font color ="red">#success_msg.FileContent#</font></P></cfoutput>            

    <cfelseif getBusRequest.recordcount gt 0>
<script type="text/javascript">
}
function scrollWin() {
window.scrollTo(0, 0);
 }
</script>
        <cfhttp method="Get"
            url="http://myurl/response_success_multiple.html" result="success_msg">
        <cfoutput><p><font color ="red">#success_msg.FileContent#</font></p></cfoutput>
    </cfif>  
 </cfif>


 <cfelse>

<cfform name="bus_enroll_form" method="post" action="#cgi.SCRIPT_NAME#"> 
<h3>Header </h3>
<p><em>Message indicated here&nbsp; <br />
</p>
<p>* Student's Last Name: 
  <cfinput name="st_last_name" id="st_last_name" value="" maxlength="25" type="text" required="yes" message="Enter Last Name" validate="noblanks"  validateat="onsubmit" style="width:150px; border:solid 1px ##ACACAC;">
</p>
<p>* Student's First Name:

    <cfinput name="st_first_name" id="st_first_name" value="" size="25" maxlength="25" type="text" required="yes" message="Enter First Name" validate="noblanks" validateat="onsubmit" style="width:100px; border:solid 1px ##ACACAC;">
  </p>
<p>Student's Middle Name:
  <cfinput name="st_middle_name" id="st_middle_name" value="" size="25" maxlength="25" type="text" style="width:100px; border:solid 1px ##ACACAC;"> 
</p>
<p>*Student's Birthdate: 
  <cfselect name="birth_month" style="width:90px;border:solid 1px ##ACACAC;" > 
<option value="1" selected="selected">Month</option>
<option value="01">January - 01</option>
<option value="02">February - 02</option>
<option value="03">March - 03</option>
<option value="04">April- 04</option>
<option value="05">May - 05</option>
<option value="06">June - 06</option>
<option value="07">July - 07</option>
<option value="08">August - 08</option>
<option value="09">September - 09</option>
<option value="10">October - 10</option>
<option value="11">November - 11</option>
<option value="12">December - 12</option> </cfselect> - <cfselect name="birth_day" style="width:60px;border:solid 1px ##ACACAC;"> 
<option value="1" selected="selected">Day</option>
<option>01</option>
<option>02</option>
<option>03</option>
<option>04</option>
<option>05</option>
<option>06</option>
<option>07</option>
<option>08</option>
<option>09</option>
<option>10</option>
<option>11</option>
<option>12</option>
<option>13</option>
<option>14</option>
<option>15</option>
<option>16</option>
<option>17</option>
<option>18</option>
<option>19</option>
<option>20</option>
<option>21</option>
<option>22</option>
<option>23</option>
<option>24</option>
<option>25</option>
<option>26</option>
<option>27</option>
<option>28</option>
<option>29</option>
<option>30</option>
<option>31</option> </cfselect> - <cfselect name="birth_year" style="width:75px;border:solid 1px ##ACACAC;"> 
<option value="2010" selected="selected">Year</option> <cfloop index="year" from="#DateFormat(DateAdd("yyyy", -4, Now()),"YYYY")#" to="#DateFormat(DateAdd("yyyy", -20, Now()),"YYYY")#" step="-1"> <cfoutput>
<option>#year#</option></cfoutput> </cfloop> </cfselect> </p>
<p>*Student's School: 

<cfquery datasource="Transportation" name="fldcodes" cachedwithin="#CreateTimeSpan(0, 1, 0, 0)#"> 
SELECT SCHNO as CODE, 
RTRIM(SHORTNAME) as DESCRIPTION 
FROM JL_TBLSSSI 
WHERE SCHLEVEL IN 
('E','M','H')  and (SchoolOpenclose = 'O'  OR SCHNO='461') and CHARTER IS NULL and SCHTYPE <> 'S'  and (C IS NULL or C = 'C' or SCHNO = '816') and SCHNO NOT IN (466,530,742,407,542,740,743,618)
UNION 
SELECT '' as CODE, ' -Select One- ' as DESCRIPTION
UNION 
SELECT '0618' as CODE, 'MANN MS' as DESCRIPTION 
ORDER BY DESCRIPTION 
</cfquery> 
<cfselect name="SchNum" id="SchNum" query="fldcodes" value="CODE" display="DESCRIPTION"  onchange="showRoutes();showRoutespm();" style="border:solid 1px ##ACACAC;" required="yes"   message="Please Select a School"> </cfselect> 
Student's Grade: 
<cfselect name="grade" style="border:solid 1px ##ACACAC;"> 
<option selected="selected">K</option>
<option>01</option>
<option>02</option>
<option>03</option>
<option>04</option>
<option>05</option>
<option>06</option>
<option>07</option>
<option>08</option>
<option>09</option>
<option>10</option>
<option>11</option>
<option>12</option> </cfselect> </p>
<p>Parent/Guardian Email Address: <cfinput name="pg_email" class="cleardefault" id="pg_email" type="text" style="width:250px; border:solid 1px ##ACACAC;" required="no" validate="email" message="Please enter a valid email address" maxlength="50"> 
</p>
<div id="RouteList" style="width: 650px, float:left; display: inline"></div>

<div id="RouteListTitlePM" id="RouteListTitlePM" style="width: 650px, float:left;visibility: hidden;"> <h3>AFTER SCHOOL  BUS SERVICE REQUEST  </h3></div>   
  <p>*Purpose of after school bus service request: from school to 
  <cfselect name="busPurpose" onchange="if (this.selectedIndex==1){document.getElementById('AfterSchoolPrgm').style.display='block'; this.form['ap_address'].style.visibility='visible'}else {document.getElementById('AfterSchoolPrgm').style.display='none'; this.form['ap_address'].style.visibility='hidden'};" style="border:solid 1px ##ACACAC;"> 
<option selected="selected" value="Home">Home</option>
<option value="After School Program">After School Program</option>
<option value="Other">Other</option> </cfselect></p>


<div style="display:none" id="AfterSchoolPrgm">
    *After School Program Name: <cfinput style="color: rgb(102, 102, 102);border:solid 1px ##ACACAC;" class="cleardefault" name="ap_name" value="" size="45" maxlength="45" type="text" ><br /><br />


    *After School Program Address:<cfinput style="color: rgb(102, 102, 102);border:solid 1px ##ACACAC;" class="cleardefault" name="ap_address" value="" size="80" maxlength="80" type="text" onvalidate="checkPurpose" message="After School Program Name and Address are required."> <br /><br />
</div>
<div id="RouteListPM" style="width: 650px, float:left; display: inline"></div>
        <cfhttp method="Get"
            url="http://myurl/form_legal.html" result="legal_msg">
        <cfoutput>#legal_msg.FileContent#</cfoutput>
  <p><cfinput name="checkbox" id="checkbox" type="checkbox" required="yes" message="Please review and accept legal disclaimer" validateat="onsubmit"  style="width:20px">I, the parent guardian of the above student, have carefully reviewed, understand,
    and accept the provisions set forth in this Request for Transportation
    Services form.</p>

<p>
    <cfinput name="submit" value="Request" type="submit" size="20" style="width:100px" class="button" onvalidate="checkBusroutes" validateat="onsubmit" validate="noblanks"  message="Please select a Morning or Afternoon Bus Route" onclick="goToAnchor;">
    <cfinput name="action" type="hidden" value="RequestBus">
  </p>
</cfform>
</cfif>

</body>

</html>
Kyle
  • 21
  • 6
  • there are syntax errors in that code. Does this run on the server? We will need to see the actual code that is being executed on the page. – Matt Busche Sep 01 '15 at 15:57
  • Yes, this is the code that is executing - no errors are being thrown, although I'm not surprised that there are problems with it. I'll update with the full code. – Kyle Sep 01 '15 at 16:18
  • 1
    No errors in your browser console? As Matt says, the Javascript is invalid syntax. You have a closing `}` before the `scrollWin` function is created. – John Whish Sep 01 '15 at 16:19
  • Open the console and look for errors. If your JavaScript is starting with a } (as your code shows) that's the issue. – Matt Busche Sep 01 '15 at 16:22
  • None of the errors in the console relate to the javascript code - there's just a couple of errors with some background/gradient images not being resolved – Kyle Sep 01 '15 at 16:26

0 Answers0