6 Replies Latest reply on May 22, 2006 3:25 AM by DJ_Jamba

    Format JS var inside JS function with CF!

    DJ_Jamba Level 1
      OK - I'll try and explain:
      I want to use CF (MX6) to format a js variable while inside a js function:

      e.g:
      <cfoutput>
      <script language="JavaScript" type="text/javascript">
      function formatSomething() {
      var something = "#DateFormat('02/04/06','dd MMM yyyy')#";
      alert(something);
      }
      </script>
      </cfoutput>

      Now this is ok if I hardcode the value of 'something'. What if I want to pass 'something' in?

      <cfoutput>
      <script language="JavaScript" type="text/javascript">
      function formatSomething(something) {
      var somethingElse = "#DateFormat('"+something+"','dd MMM yyyy')#";
      alert(somethingElse);
      }
      </script>
      </cfoutput>

      Of course this doesn't work! - Neither does:
      var somethingElse = eval("#DateFormat('"+something+"','dd MMM yyyy')#");
      var somethingElse = "#Evaluate(DateFormat('"+something+"','dd MMM yyyy'))#";
      var somethingElse = eval("#Evaluate(DateFormat('"+something+"','dd MMM yyyy'))#");

      It's not specifically dates either - I just want to know if it's possible to do this someway?
      I'm currently looking at opening a child window off screen to do what I want and pass back to the JS function but it seems like an urrggggghhh way to do it..

      Ta for any help...