HTML, JavaScript And CSS Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Iron Speed
Go Back   ASP Free ForumsProgrammingHTML, JavaScript And CSS Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old May 7th, 2008, 09:11 AM
EM2 EM2 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 38 EM2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 14 m 43 sec
Reputation Power: 1
Incremental Variables

I've got an ASP page where variables are added as the user inputs more data and they're named "Changed + i" where i is an incremental variable. So I have Changed1, Changed2, Changed3 and it continues. I want to run a for loop through these variables and check to see if the value of any of them equals another value. So I'm wondering how I can run a check on changed + i and how I refer to the name of the variable dynamically.

I forgot to mention this is in a javascript function on the page.

Reply With Quote
  #2  
Old May 7th, 2008, 09:19 AM
sync_or_swim's Avatar
sync_or_swim sync_or_swim is offline
Contributing User
ASP Free Beginner (1000 - 1499 posts)
 
Join Date: Mar 2006
Location: South Wales
Posts: 1,025 sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level) 
Time spent in forums: 2 Weeks 6 Days 4 h 38 m 59 sec
Reputation Power: 608
Can you post any code that you have so far?

You should simply be able to use a loop to loop through them, something like this (not tested):
Code:
<script>
for(var a=1;a<=10;a++){
  if(document.myform.elements["Changed"+a].value=="test"){
     //condition is true!!
  }
}
</script>

Reply With Quote
  #3  
Old May 7th, 2008, 09:27 AM
EM2 EM2 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 38 EM2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 14 m 43 sec
Reputation Power: 1
Thank you, you just helped me put together this working script:

Code:
	var i=0;
	for (i=1;i<=25;i++)
	{
		if (document.frmUser.elements["CHANGED"+i].value=="T")
		{
			alert('error3');
			if (document.frmUser.elements["Manage_Area_Name"+i].value == "XXX")
			{
				alert('error1');
			}
			else
			{
				alert('error2');
			}
		}
	}


How do I find out how many times to go through the loop now?

Reply With Quote
  #4  
Old May 7th, 2008, 09:33 AM
sync_or_swim's Avatar
sync_or_swim sync_or_swim is offline
Contributing User
ASP Free Beginner (1000 - 1499 posts)
 
Join Date: Mar 2006
Location: South Wales
Posts: 1,025 sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level) 
Time spent in forums: 2 Weeks 6 Days 4 h 38 m 59 sec
Reputation Power: 608
Quote:
Originally Posted by EM2
How do I find out how many times to go through the loop now?

Sorry, I don't understand, how are you constructing the form? Will the number of textboxes change?

Reply With Quote
  #5  
Old May 7th, 2008, 09:37 AM
EM2 EM2 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 38 EM2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 14 m 43 sec
Reputation Power: 1
Yes, it's a list of items being pulled from a database and each one is given a name of CHANAGEDi where the variable i is an incremental number, different for each variable. So right now there's CHANGED1......CHANGED25 and if the user creates a new mamber in the database, there will be a CHANGED26 on the page as well. So I want to be able to run a single script that iwll run through all of them and do a comparison. The script I just posted works for right now but it's set to 25 loops, I was wondering how to get it to loop for the amount of CHANGEDi elements in the form.

Just to try and help a little more, I have a bunch of locations in the database and when the page loads it uses ASP/SQL to display each location on the page and named in a CHANGEDi sequence. If the user enters another location and clicks UPDATE or if they edit any of the existing locations and click UPDATE, I want to first do a check to make sure that location isn't already in the database before submitting the form. That's the long story. So if the user edits any of the fields, it does an onchange function to change the CHANGEDi value to "T". On an onsubmit, I want to cycle through all CHANGEDi elements and see if any of their values equal "T". If so, I want to get the value of the corresponding location and compare it to every element in the database to see if it's already in there.

I can do a lot of it on my own but need help with a few things.

Reply With Quote
  #6  
Old May 7th, 2008, 09:37 AM
sync_or_swim's Avatar
sync_or_swim sync_or_swim is offline
Contributing User
ASP Free Beginner (1000 - 1499 posts)
 
Join Date: Mar 2006
Location: South Wales
Posts: 1,025 sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level) 
Time spent in forums: 2 Weeks 6 Days 4 h 38 m 59 sec
Reputation Power: 608
I will have to see your full code before I can help more, but if you are pulling the records from a database you could also increment a counter as you do it, and store this value somewhere on your form:
Code:
Dim numberofboxes
numberofboxes = 0
sql = "select * from yourtable"
'etc....

While NOT rs.EOF
   'do something
   numberofboxes = numberofboxes + 1
   rs.Movenext
Wend
Response.Write("<input type=""text"" name=""howmany"" value=""" & numberofboxes & "">")

You could then use this value as the upper bound of your loop:
Code:
var howmany = document.yourform.howmany.value;
for(var a=1;a<=howmany;a++){
//etc...

Last edited by sync_or_swim : May 7th, 2008 at 09:40 AM.

Reply With Quote
  #7  
Old May 7th, 2008, 10:01 AM
EM2 EM2 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 38 EM2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 14 m 43 sec
Reputation Power: 1
I just realized you may be waiting to see my code. Here's the part populating the locations onto the page:

Code:
<%
	If not rs_Users.EOF then
	rs_Users.movefirst
	
	Do While NOT rs_Users.EOF 
		Count = Count + 1

		If ColorOn = False then
			Response.Write "<TR Class=white>"
			For x = 0 to fldCount - 1
				Response.Write "<TD Class=small><INPUT NAME=" & CHR(34) & fieldnames(x) & Count & CHR(34) & " ONCHANGE=vbscript:Document.frmUser.CHANGED" & Count & ".Value=" & CHR(34) & "T" & CHR(34) & " TYPE=TEXT CLASS=INPUTWHITE VALUE=" & CHR(34) & trim(rs_Users.Fields.item(x)) & CHR(34) & "></INPUT></TD>" & vbCRLF
			Next
			Response.Write "<TD><Input NAME=CHANGED" & Count & " CLASS=INPUTWHITE TYPE=HIDDEN SIZE=1 MAXLENGTH=1></INPUT></TD>" & vbCRLF & vbCRLF
			ColorOn = True
		Else
			Response.Write "<TR Class=blue>"
			For x = 0 to fldCount - 1
				Response.Write "<TD Class=small><INPUT NAME=" & CHR(34) & fieldnames(x) & Count & CHR(34) & " ONCHANGE=vbscript:Document.frmUser.CHANGED" & Count & ".Value=" & CHR(34) & "T" & CHR(34) & " TYPE=TEXT CLASS=INPUTBLUE VALUE=" & CHR(34) & trim(rs_Users.Fields.item(x)) & CHR(34) & "></INPUT></TD>" & vbCRLF
			Next
			Response.Write "<TD><Input NAME=CHANGED" & Count & " CLASS=INPUTBLUE TYPE=HIDDEN SIZE=1 MAXLENGTH=1></INPUT></TD>" & vbCRLF & vbCRLF
			ColorOn = False
		End If


		Response.Write "</TR>"
		rs_Users.Movenext
	Loop
	End if
%>	

Reply With Quote
  #8  
Old May 7th, 2008, 10:01 AM
EM2 EM2 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 38 EM2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 14 m 43 sec
Reputation Power: 1
It displays it with either a white or blue background for easier reading (as usual) and the page source looks like so:

Code:
</TR><TR Class=blue><TD Class=small><INPUT NAME="Area_ID18" ONCHANGE=vbscript:Document.frmUser.CHANGED18.Value  ="T" TYPE=TEXT CLASS=INPUTBLUE VALUE="AM5"></INPUT></TD>
<TD Class=small><INPUT NAME="Area_Mgr18" ONCHANGE=vbscript:Document.frmUser.CHANGED18.Value  ="T" TYPE=TEXT CLASS=INPUTBLUE VALUE="Norihisa Dobashi"></INPUT></TD>
<TD Class=small><INPUT NAME="AREA_MGRJP18" ONCHANGE=vbscript:Document.frmUser.CHANGED18.Value  ="T" TYPE=TEXT CLASS=INPUTBLUE VALUE="土橋律久"></INPUT></TD>
<TD Class=small><INPUT NAME="Manage_Area_Name18" ONCHANGE=vbscript:Document.frmUser.CHANGED18.Value  ="T" TYPE=TEXT CLASS=INPUTBLUE VALUE="Higashi Tokyo"></INPUT></TD>
<TD Class=small><INPUT NAME="Regional_Mgr_ID18" ONCHANGE=vbscript:Document.frmUser.CHANGED18.Value  ="T" TYPE=TEXT CLASS=INPUTBLUE VALUE="2"></INPUT></TD>
<TD><Input NAME=CHANGED18 CLASS=INPUTBLUE TYPE=HIDDEN SIZE=1 MAXLENGTH=1></INPUT></TD>

</TR><TR Class=white><TD Class=small><INPUT NAME="Area_ID19" ONCHANGE=vbscript:Document.frmUser.CHANGED19.Value  ="T" TYPE=TEXT CLASS=INPUTWHITE VALUE="AM6"></INPUT></TD>
<TD Class=small><INPUT NAME="Area_Mgr19" ONCHANGE=vbscript:Document.frmUser.CHANGED19.Value  ="T" TYPE=TEXT CLASS=INPUTWHITE VALUE="Masako Tsuneki"></INPUT></TD>
<TD Class=small><INPUT NAME="AREA_MGRJP19" ONCHANGE=vbscript:Document.frmUser.CHANGED19.Value  ="T" TYPE=TEXT CLASS=INPUTWHITE VALUE="常木昌*"></INPUT></TD>
<TD Class=small><INPUT NAME="Manage_Area_Name19" ONCHANGE=vbscript:Document.frmUser.CHANGED19.Value  ="T" TYPE=TEXT CLASS=INPUTWHITE VALUE="Tokyo Mid"></INPUT></TD>
<TD Class=small><INPUT NAME="Regional_Mgr_ID19" ONCHANGE=vbscript:Document.frmUser.CHANGED19.Value  ="T" TYPE=TEXT CLASS=INPUTWHITE VALUE="2"></INPUT></TD>
<TD><Input NAME=CHANGED19 CLASS=INPUTWHITE TYPE=HIDDEN SIZE=1 MAXLENGTH=1></INPUT></TD>


That's numbers 18 and 19 as you can see, there's 25 in total. Does that help?

Reply With Quote
  #9  
Old May 8th, 2008, 03:43 AM
sync_or_swim's Avatar
sync_or_swim sync_or_swim is offline
Contributing User
ASP Free Beginner (1000 - 1499 posts)
 
Join Date: Mar 2006
Location: South Wales
Posts: 1,025 sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level)sync_or_swim User rank is Brigadier General (60000 - 70000 Reputation Level) 
Time spent in forums: 2 Weeks 6 Days 4 h 38 m 59 sec
Reputation Power: 608
Hi,

Thanks for posting your code, it helps me to see exactly what is going on.

You know the number of records because you are incrementing a counter so store this value on your form something like this:
Code:
<%
	If not rs_Users.EOF then
	rs_Users.movefirst
	
	Do While NOT rs_Users.EOF 
		Count = Count + 1

		If ColorOn = False then
			Response.Write "<TR Class=white>"
			For x = 0 to fldCount - 1
				Response.Write "<TD Class=small><INPUT NAME=" & CHR(34) & fieldnames(x) & Count & CHR(34) & " ONCHANGE=vbscript:Document.frmUser.CHANGED" & Count & ".Value=" & CHR(34) & "T" & CHR(34) & " TYPE=TEXT CLASS=INPUTWHITE VALUE=" & CHR(34) & trim(rs_Users.Fields.item(x)) & CHR(34) & "></INPUT></TD>" & vbCRLF
			Next
			Response.Write "<TD><Input NAME=CHANGED" & Count & " CLASS=INPUTWHITE TYPE=HIDDEN SIZE=1 MAXLENGTH=1></INPUT></TD>" & vbCRLF & vbCRLF
			ColorOn = True
		Else
			Response.Write "<TR Class=blue>"
			For x = 0 to fldCount - 1
				Response.Write "<TD Class=small><INPUT NAME=" & CHR(34) & fieldnames(x) & Count & CHR(34) & " ONCHANGE=vbscript:Document.frmUser.CHANGED" & Count & ".Value=" & CHR(34) & "T" & CHR(34) & " TYPE=TEXT CLASS=INPUTBLUE VALUE=" & CHR(34) & trim(rs_Users.Fields.item(x)) & CHR(34) & "></INPUT></TD>" & vbCRLF
			Next
			Response.Write "<TD><Input NAME=CHANGED" & Count & " CLASS=INPUTBLUE TYPE=HIDDEN SIZE=1 MAXLENGTH=1></INPUT></TD>" & vbCRLF & vbCRLF
			ColorOn = False
		End If


		Response.Write "</TR>"
		rs_Users.Movenext
	Loop
	End if
Response.Write("<input type=""text"" name=""howmany"" value=""" & Count & "">")%>	

Then use this value in your javascript loop (I can't see what you form is called, change the name accordingly):
Code:
var howmany = document.yourform.howmany.value;
for(var a=1;a<=howmany;a++){
//etc...

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingHTML, JavaScript And CSS Help > Incremental Variables


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

Iron Speed




© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway