Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2004
    Location
    Oslo
    Posts
    45

    Unanswered: <%Recset.Movenext%> won't work in JS Iteration. Please help :)

    Hi there

    Most of the code here is Javascript, but the problem-code is infact the ASP code in it..

    i've tried to print out the value of postRs("postnr") and postRs("poststed") for each iteration , but it's not doing what should be done :
    <%postRs.Movenext%>..

    Is there another way to do what i'm trying to do ?

    -----------------SQL QUERIES-----------------------
    <%
    Dim postRs
    objCommand.CommandText = "SELECT postnr, poststed from POSTINFO"
    set postRs = objCommand.Execute

    '<finn antall poststed og nummer>
    Dim ant
    objCommand.CommandText = "SELECT count(postnr) from POSTINFO"
    ant=objCommand.Execute
    %>
    ---------END SQL QUERIES---------------------

    --------------------JS WITH ASP-----------------
    <script language=JavaScript>
    var nrTab = new Array(<%=ant(0)%>);
    var stedTab = new Array(<%=ant(0)%>);

    var iCount = 0;

    <%postRs.MoveFirst%>

    while (iCount < <%=ant(0)%>)
    {
    nrTab[iCount] = '<%=postRs("postnr")%>';
    stedTab[iCount] = '<%=postRs("poststed")%>';
    <%postRs.MoveNext%>
    iCount++;

    }

    alert(stedTab[iCount]);


    </script>
    Best regards
    Mirador

  2. #2
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    Well it kinda looks fine to be honest. My only question would be is this all the code. Or is you JS inside a loop for iterating through the recordset?? If not the code you are showing will only work for the first record and then ignore the others because there is no loop.

  3. #3
    Join Date
    Jan 2004
    Location
    Oslo
    Posts
    45

    Unhappy

    Hey there, and thanx for the reply

    Well.. it's all the code infact.. (except code for db connection and that..
    I haven't made the code for displaying into a field and all that (front-end) but i have tried to :

    1)
    Run a --> alert('<%=postRs("postnr")%>'); just before the <%postRs.MoveNext%> to see if it loops, and it dont seem soo, cause it's returning the same value x number of times of posts in the database.

    2)
    Run a --> alert(stedTab[iCount]); to check for the same, but same happens.

    The weird thing is though.. if i put the alert('<%=postRs("postnr")%>'); _BEFORE_ the MoveNext, it returns the _first_ post in the database, if i put it right _AFTER_ the MoveNext, it returns the _second_ post in the database.
    This proves that there's _some_ kind of loop going on, but i cannot figure out why it stops (if first postnr is "110" it writes "110" for x number of posts in the db, if the second post is "114" it writes "114" for x number of posts..

    I have altso checked that the asp-variable ant(0) is showing the correct amount of posts in the db.

    Weird isn't it ?

    Will be forever-happy-happy if anyone know what this bugger of a code can be
    Best regards
    Mirador

  4. #4
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    if that is all the code then it is not weird at all.... try this...
    Code:
    -----------------SQL QUERIES-----------------------
    <%
    Dim postRs
    objCommand.CommandText = "SELECT postnr, poststed from POSTINFO"
    set postRs = objCommand.Execute
    
    '<finn antall poststed og nummer>
    Dim ant
    objCommand.CommandText = "SELECT count(postnr) from POSTINFO"
    ant=objCommand.Execute
    %>
    ---------END SQL QUERIES---------------------
    
    --------------------JS WITH ASP-----------------
    <script language=JavaScript>
    var nrTab = new Array(<%=ant(0)%>);
    var stedTab = new Array(<%=ant(0)%>);
    
    var iCount = 0;
    
    <%
    Do while not postRs.eof
    %>
    while (iCount < <%=ant(0)%>) 
    {
    nrTab[iCount] = '<%=postRs("postnr")%>';
    stedTab[iCount] = '<%=postRs("poststed")%>';
    <%postRs.MoveNext
    Loop
    %>
    iCount++; 
    
    } 
    
    alert(stedTab[iCount]);
    
    </script>
    Note the do while and the loop statements....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •