Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,472
There are 1704 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     PHP and MySQL :

Javascript

Thread title: Javascript
Closed Thread    
    Thread tools Search this thread Display Modes  
12-18-2005, 02:50 AM
#1
Sketch is offline Sketch
Sketch's Avatar
Status: Member
Join date: Aug 2005
Location: Melbourne, Australia
Expertise:
Software:
 
Posts: 419
iTrader: 0 / 0%
 

Sketch is on a distinguished road

  Old  Javascript

I have a validation section in some of my code. It's pretty simple, but the problem is there is 10 sections to it. I don't want to have to write out all 10 sections, I just want to write out one and get a loop to do the rest.

Is there any way to do this?

Code:
			if(document.RealEstate.INSPECTION_TIME_D1.value != "----") {
			
					alert("Error!\nYou have started Inspection #1 but you have not completed it.");
					return false;
				}			
			}
I want something like

Code:
for(x = 0; x !=; x++) {
if(document.RealEstate.INSPECTION_TIME_D+x+.value != "----") {
			
					alert("Error!\nYou have started Inspection #" + x + "but you have not completed it.");
					return false;
				}			
			}
}
Notice in the if statement, the INSPECTION_TIME_D is +x+ not 1. I want the X to replace the number.

I hope this makes sense, I'm sure its easy to do I'm just not sure how to do it.

12-19-2005, 01:49 AM
#2
Salathe is offline Salathe
Salathe's Avatar
Status: Community Archaeologist
Join date: Jul 2004
Location: Scotland
Expertise: Software Development
Software: vim, PHP
 
Posts: 3,820
iTrader: 25 / 100%
 

Salathe will become famous soon enough

Send a message via MSN to Salathe

  Old

You might like to try using the following if statement:

Code:
if(document.RealEstate["INSPECTION_TIME_D"+x] && (document.RealEstate["INSPECTION_TIME_D"+x].value != "----")) {
That checks if document.RealEstate.INSPECTION_TIME_Dx exists and if its value property doesn't equal "----". The first check isn't 100% necessary but trying to get the value will throw up JS errors if the item doesn't exist.

Closed Thread    


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed