2 Replies Latest reply on Mar 4, 2010 10:55 AM by beades

    onclick event in cfscript?

    beades Level 1

      I have been through this discussion list and another and cannot find an answer to my problem.  I'm hoping someone can help.

       

      I am wanting to use a calendar script I found (WriteCalendar at www.cflib.org/udf.cfm?id=540) that is written in cfscript.

       

      <cfscript>
      /**
      * Produces a Calendar for a given month and year.
      *
      * @param curMonth      The month to display.
      * @param curYear      The year to display.
      * @param height      Height of the table cells. Defaults to 40.
      * @param width      Width of the table cells. Defaults to 60.
      * @param titleStyle      Style to apply to title row.
      * @param numberStyle      Style to apply to days of the month.
      * @return Returns a string.
      * @author William Steiner (williams@hkusa.com)
      * @version 1, April 12, 2002
      */
      function createCalendar(curMonth,curYear) {
          var outString = "";
          var firstDay = CreateDate(curYear, curMonth, 1);
          var firstDayDigit = DayOfWeek(FirstDay);
          var i = 1;
          var h = 1;
          var height = 40;
          var width = 60;
          var titleStyle = "";
          var numberStyle = "";

          if(arrayLen(arguments) gte 3) height = arguments[3];
          if(arrayLen(arguments) gte 4) width = arguments[4];       
          if(arrayLen(arguments) gte 5) titleStyle = arguments[5];
          if(arrayLen(arguments) gte 6) numberStyle = arguments[6];
         
          outString = "<table border='1'><tr><td align=center colspan='7'  ";
          if(len(titleStyle)) outString = outString & "class='#titleStyle#'";
          outString = outString & ">#DateFormat(firstDay, 'mmmm')#</td></tr>";
         
          // if it isn't sunday, then we need to if space over to start on the corrent day of week
          if (firstDayDigit neq 1) {
              for (h=1; h lt DayOfWeek(FirstDay); h = h+1) {
                  outString = outString & "<td> </td>";
              }
          }
         
          // loop thru all the dates in this month
          for (i=1; i lte DaysInMonth(firstDay); i = i+1) {
              //is it Sunday? if so start new row.
              if (DayOfWeek(CreateDate(curYear, curMonth, i)) eq 1) {
                  outString = outString & "<tr>";
              }
              // insert a day
              outString = outString & "<td align='left' valign='top' width='#width#px' ";
              if(len(numberStyle)) outString = outString & "class='#numberStyle#' ";
              outString = outString & "height='#height#'>#i#<br></td> ";
              // is it the last day of the month?  if so, fill row with blanks.
              if (i eq DaysInMonth(firstDay)) {
                  for (h=1; h lte (7-DayOfWeek(CreateDate(curYear, curMonth, i))); h = h+1) {
                      outString = outString & "<td> </td>";
                  }
              }
              if (DayOfWeek(CreateDate(curYear, curMonth, i)) eq 7){
                  outString = outString & "</tr>";
              }
          }
          outString=outString & "</table>";
          return outString;
      }
      </cfscript>

       

       

       

      For the line  outString = outString & "height='#height#'>#i#<br></td> ";, I would like to modifly that to allow a user to click on the day and have that date be sent to a form field called selectedDate.  This can the be submitted and used to create a room schedule table.

       

      I know in javascript I can set an onclick that will then populate a form value.  Is there an equivalent in cfscript?  I have looked here and everyone notes that I cannot use javascript within cfscript.

       

      Is this one where it cannot be done?  I hope it can.  Any help is greatly appreciated.

       

      Thank you!

       

      Lynn

        • 1. Re: onclick event in cfscript?
          ilssac Level 5

          You are confusing your cfscript and your javascript.

           

          Cfscript is simply a script form of the normal cfml tag based syntax.  It does the same thing in the same place.  I.E. it runs on the server and builds a response that is returned to the web server to be forwarded to the client, where the response is parsed into a user interface.

           

          JavaScript is a script based language meant to run on the client.  It does not run on the ColdFusion server.  But it is very easy to have CFML create JavaScript code as part of the response it sends to the client where that JavaScript can be ran.

           

          So to answer your ultimate question.  Put that JavaScript code that you know how to use to populate a form field into the outString variable that is building the response to be sent to the client and the client will happily run it for you.  Assuming you get the syntax correct.

           

          The only usual difficulty can be seperating delimiters, often single and double quote characters making sure you, the server and the client know which ones are to be used on the server and which ones are to be used on the client.

           

          I.E. A simple example  outString = outString & "height='#height#' onClick='alert(""Hello, you clicked me"")'>#i#<br></td>"

          1 person found this helpful
          • 2. Re: onclick event in cfscript?
            beades Level 1

            Ian,

             

            Thank you so much for clearing this up for me.  I really appreciate it.

             

            I got the form to work perfectly!

             

            Thank You!!!

             

            Lynn