Loading ...
Sorry, an error occurred while loading the content.
 

Question in java script and asp classic

Expand Messages
  • bigdeathman
    Dear all , i have a small question in java script: i want to write a select statment to retreive some data froma table by the asp classic within a java script
    Message 1 of 2 , Aug 1, 2006
      Dear all ,
      i have a small question in java script: i want to write a select
      statment to retreive some data froma table by the asp classic within a
      java script function... that's my code to do so:

      <%sqlid="select id from description where desc_code = '" var "'" %>;
      <%set rsid=server.createobject("adodb.recordset")%>
      <%rsid.open sqlid,cn,3%>
      alert("count = " + <%=rsid.recordcount%>);

      var is a variable that contain a value and i'm sure that it is not
      empty, but this piece of code give me alert saying: count = 0
      but if i wrote the code like that:

      <%sqlid="select id from description where desc_code = 20" %>;
      <%set rsid=server.createobject("adodb.recordset")%>
      <%rsid.open sqlid,cn,3%>
      alert("count = " + <%=rsid.recordcount%>);

      the alert say: count = 1
      which mean that the first code cannot contain the value (20) from the
      variable (var)

      help please
      thanks in advance
    • Jon Stephens
      ... The ASP code is evaluated, *then* the result sent to the client. var is a clientside variable, and so is not yet defined when the serverside code is
      Message 2 of 2 , Aug 1, 2006
        > Question in java script and asp classic
        > Posted by: "bigdeathman" bigdeathman@... bigdeathman
        > Date: Tue Aug 1, 2006 9:28 am (PDT)
        >
        > Dear all ,
        > i have a small question in java script: i want to write a select
        > statment to retreive some data froma table by the asp classic within a
        > java script function... that's my code to do so:
        >
        > <%sqlid="select id from description where desc_code = '" var "'" %>;

        The ASP code is evaluated, *then* the result sent to the client. var is
        a clientside variable, and so is not yet defined when the serverside
        code is executed.

        You'd need to get all possible values for the code with the
        corresponding counts first, write those to a clientside JS array, then
        get the value from the clientside array. Something like this:

        <%
        Response.write "var counts = [];"
        For I=1 To 20
        SqlId = "SELECT id FROM description WHERE desc_code = " & I
        Set RSId = Server.CreateObject("ADODB.RecordSet")
        RSId.Open SqlId,Conn,3
        Response.Write "counts[" & I & "] = " & RSId.RecordCount & ";"
        Next
        %>

        alert("Count = " + counts[var]);

        If your database supports GROUP BY queries, then you could just use
        something like

        SELECT desc_code,COUNT(*) FROM description GROUP BY desc_code

        for the query, and loop through its result set to write the clientside
        JS array keys and values.



        > <%set rsid=server.createobject("adodb.recordset")%>
        > <%rsid.open sqlid,cn,3%>
        > alert("count = " + <%=rsid.recordcount%>);
        >
        > var is a variable that contain a value and i'm sure that it is not
        > empty, but this piece of code give me alert saying: count = 0
        > but if i wrote the code like that:
        >
        > <%sqlid="select id from description where desc_code = 20" %>;
        > <%set rsid=server.createobject("adodb.recordset")%>
        > <%rsid.open sqlid,cn,3%>
        > alert("count = " + <%=rsid.recordcount%>);
        >
        > the alert say: count = 1
        > which mean that the first code cannot contain the value (20) from the
        > variable (var)
        >
        > help please
        > thanks in advance
        >
        >
        >
        >
        >
        >
        >

        --
        This message has not been scanned for viruses.

        Since I do not use a Microsoft operating
        system or software, and use only plaintext
        for email, there is little need for me to do so.
      Your message has been successfully submitted and would be delivered to recipients shortly.