469,323 Members | 1,500 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,323 developers. It's quick & easy.

Does MoveNext work in a loop in Javascript?

Hope I can get some help here...

I connect to an SQL database using ASP. I can see the records. I have a small (very basic) function written in Javascript. When I use the MoveNext in the function, it works fine. However, when I use it inside of a loop, the MoveNext does not work. Is this a known problem? Please help.

This is where I connect to the database from ASP:

Expand|Select|Wrap|Line Numbers
  1. <% 
  2. Dim DeptID 
  3. Dim DeptID_numRows 
  4.  
  5. Set DeptID = Server.CreateObject("ADODB.Recordset") 
  6. DeptID.ActiveConnection = MM_A_CRS_STRING 
  7. DeptID.Source = "SELECT * FROM dbo.mstrPersonnel ORDER BY ID ASC" 
  8. DeptID.CursorType = 0 
  9. DeptID.CursorLocation = 2 
  10. DeptID.LockType = 2 
  11. DeptID.Open() 
  12.  
  13. DeptID_numRows = 0 
  14. %> 
  15.  
Now here is the function is javascript:

The MoveNext command NEVER works inside of the LOOP but works anywhere else in the function.

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript"> 
  2. function Owner() { 
  3. <% DeptID.MoveFirst() %>; 
  4. var y = "<%= Session("TotalRec") %>"; // is total number of record in recordset 
  5. alert ("y from session = " + y); 
  6. <% DeptID.MoveFirst() %>; 
  7. alert(" <%=(DeptID.Fields.Item("DeptID").Value)%>" + " from pull dowm = " + document.frmCRSContract.Department_ID.value + " Current Record ID = " + "<%=(DeptID.Fields.Item("ID").Value)%>") 
  8. <%DeptID.MoveNext()%>; 
  9. alert(" <%=(DeptID.Fields.Item("DeptID").Value)%>" + " from pull dowm = " + document.frmCRSContract.Department_ID.value + " Current Record ID = " + "<%=(DeptID.Fields.Item("ID").Value)%>") 
  10.  
  11. var x = 1; 
  12. while (x <= y) 
  13. <%DeptID.MoveNext()%>; 
  14. alert(" in loop Current deptID = " + "<%=(DeptID.Fields.Item("DeptID").Value)%>" + " from pull dowm = " + document.frmCRSContract.Department_ID.value + " Current Record ID = " + "<%=(DeptID.Fields.Item("ID").Value)%>"); 
  15. x = x + 1 
  16. } // End of LOOP 
  17. alert(" deptID = " + "<%=(DeptID.Fields.Item("DeptID").Value)%>"); 
  18. } // end Function 
  19.  
  20. </script>
Apr 26 '07 #1
2 2507
JosAH
11,448 Expert 8TB
Moved this question from the Java forum.

kind regards,

Jos
Apr 26 '07 #2
acoder
16,027 Expert Mod 8TB
ASP and JavaScript can't be mixed like that. JavaScript is client-side while ASP is server-side. Once the page has loaded, you can't run ASP code unless you use Ajax/iframes. The reason why it works outside the loop is that it's during page load, but the loop is a JavaScript loop which will loop after the page has loaded. You can use ASP code for looping to display all results for use in the JavaScript code.
Jun 6 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by csx | last post: by
1 post views Thread by Foxie Foxster | last post: by
22 posts views Thread by Cogito | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by Gurmeet2796 | last post: by
reply views Thread by mdpf | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by listenups61195 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.