473,605 Members | 2,425 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 2793
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
3132
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
4690
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
11941
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
2527
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
2713
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
2099
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
2917
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
2520
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
2473
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
7931
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
8423
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
8411
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
8281
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6740
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...
0
3911
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3956
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2437
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
1
1530
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.