#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    4
    Rep Power
    0

    Unhappy Call JS functions in classic ASP tags!


    How can I call javascript functions, locate in <head> section, in a query list in ASP tags?
    This is an example I need to format dates:
    Head page code:
    Code:
    <head>
    <meta http-equiv="Content-Language" content="pt">
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title> ...  ...</title>
    <script language="JavaScript"><!--
    function formataData(d) {
    		var strHoje = new Date(d);
    		var strDia = strHoje.getDate(); 
    			if (strDia < 10){ strDia = "0" + strDia }
    		var strMes = strHoje.getMonth(); 
    			strMes = strMes + 1;
    				if (strMes < 10) { strMes = "0" + strMes }
    		var strAno = strHoje.getYear();
    		var DataHoje = strDia + "-" + strMes + "-" + strAno; 
    	return DataHoje;
    }
    --></script>
    And in the middle of the page I use to try to call that function:
    Code:
    <% 	
    	var rs3 = Server.CreateObject("ADODB.Recordset");
     	strSQL3 = "Select * from Frota_consumo where UO= '" + vXu + "' order by x_matricula ASC, data_consumo DESC";
    	rs3.Open (strSQL3, conn); 
    	while (!rs3.EOF) { 
    
    	var vD1 = rs3("data_consumo");
    	var vData1 = formataData(vD1);
    	var vD2 = rs3("data_consumo");
    	var vData2 = formataData(vD2);
    	
    	vFile.WriteLine (rs3("x_matricula") + ";" + vData1 + ";" + vData2 + ";" + rs3("contagem_actual") + ";" + rs3("contagem_consumo") + ";" + rs3("litros_consumo") + ";" + rs3("custo_consumo"));
    
    %>
    I need this to be used in a list, with some date values, to export to a external file.
    Any Help? Thanks!
  2. #2
  3. No Profile Picture
    Grumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Posts
    14,436
    Rep Power
    4539
    You can't. Your js function is run on the client browser computer, but all asp code between <% .. %> tags runs on the web server. The two can't interact without some kind of ajax code acting as a go-between.
    ======
    Doug G
    ======
    Bartender to Rene Descartes "have another beer?" Descartes: "I think not" and he vanished.
    --Alfred Bester
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    1
    Rep Power
    0

    You can however do the opposite interraction if it will help


    [code]
    <%
    Option Explicit
    'On Error Resume Next

    Dim strHello : strHello = "Hello World"
    %>

    <script type="text/javascript">
    <!--

    alert (<%=strHello%>)

    //-->
    </script>

    [code]
    Last edited by wwcollins; November 14th, 2013 at 10:09 AM. Reason: spelling error

IMN logo majestic logo threadwatch logo seochat tools logo