473,789 Members | 2,190 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Does MoveNext work in a loop in Javascript?

1 New Member
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 2802
JosAH
11,448 Recognized Expert MVP
Moved this question from the Java forum.

kind regards,

Jos
Apr 26 '07 #2
acoder
16,027 Recognized Expert Moderator MVP
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

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

Similar topics

5
3145
by: Shay | last post by:
essentially I am trying to do some counts based on some assumptions in the recordset. So I get the RS back, put the values into a variable, move to the next record in the RS and compare what is in the variable to the value in the next record in the recordset and do a count. Then overwrite the value in the variables and do the same for the next record and so. But this runs extremly slow. 5000 records takes about 10 minutes in IE6 and I...
3
4705
by: csx | last post by:
Hi all, Ive got a problem with recursion in Javascript. For this tree: http://www.pcm.uklinux.net/structure.jpg If you input node 3 (i.e. C) which is represented as 'values' in the array, it should return all the 'leaf' nodes. In this case 4! Node 4 (i.e. D) is not included in the count.
4
11956
by: rick | last post by:
The following basic script works fine in firefox by not in IE. Can anyone spot the problem? In IE I can only delete the first line but not the lines created by javascript. Also, look at the HTML code for the first line (click the Table HTML button:)) you will fine that the code displayed is not the same as was written. "onChange" was changed to "onchange" etc. Please help. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">...
8
2560
by: lawrence | last post by:
I'm learning Javascript. I downloaded a script for study. Please tell me how the variable "loop" can have scope in the first function when it is altered in the second function? It is not defined in global space, therefore it is not a global variable, yes? Even if it was global, how would it get from one function to another? In PHP variables are copied by value. Are they copied by reference in Javascript? <SCRIPT LANGUAGE="JavaScript">
1
2719
by: Foxie Foxster | last post by:
i made this private sub date_afterupdate() dim huidigeDB as database dim rsklanten, rspunten as recordset set huidigedb = currentdb set reklanten= huidigeDB.openrecordset('tblleveranciers", dbopentable set rspunten = HuidigeDB.openrecordset("qrytotaalspel", dbopendynaset
8
2110
by: Brad Wood | last post by:
When I do this: foreach( Button btn in myForm.Controls ) An exception is raised when no buttons exist. I would simply expect execution to continue after the foreach loop (just as would be the case with a regular for loop when the second expression is false when the loop begins). Is there an explanation for this?
4
2933
by: bfulford | last post by:
I have a macro that needs to have a progress meter displayed since it is long running. I moved the Macro's instructions to a table and pulled those records into a recordset that is looped through. PROBLEM -- The form, with a progress meter and labels to inform the user as to which step of a series of instructions is being done and the overall progress, seems to lock from repainting after the first docmd.openquery because the form is never...
22
2540
by: Cogito | last post by:
For the first time, I'm attempting to write a small Javascript program using one on the online reference sites. I need some confirmation as to the behaviour of the break statement. In the following code: for ( row = 0 ; row <= 7 ; row++ ) A <---- { for ( col = 0 ; col <=7 ; col++ ) B <---- {
1
2480
by: MrDeej | last post by:
I have query this to filter the posts i want to work with, it is called "MAIN ompakkingskø baklager Gemba" and the sql is this: SELECT .Varenr, .Lokasjon AS Baklager, ., Left(,2) AS c FROM WHERE (((.Lokasjon) Like "*Gemba*") AND ((Left(,2))="01" Or (Left(,2))="02" Or (Left(,2))="03" Or (Left(,2))="04" Or (Left(,2))="05" Or (Left(,2))="06" Or (Left(,2))="07" Or (Left(,2))="08" Or (Left(,2))="09" Or (Left(,2))="10" Or (Left(,2))="11" Or...
0
9656
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9499
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10374
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10177
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8995
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7519
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4076
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2898
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.