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,471
There are 992 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     Javascript :

Calling the function!

Thread title: Calling the function!
Closed Thread    
    Thread tools Search this thread Display Modes  
03-01-2008, 10:54 PM
#1
Kevin_Creations is offline Kevin_Creations
Status: I'm new around here
Join date: Feb 2008
Location:
Expertise:
Software:
 
Posts: 7
iTrader: 0 / 0%
 

Kevin_Creations is on a distinguished road

  Old  Calling the function!

Hello;

I am currently trying to figure this code that I did and its just not working the way how I want it to work. Basically, I have one function that has to loop through all of the images and once it hit the third image I want it to alert out the image src information. THen the second part is I want it all of the form to alert out which part of the text box is not filled. I got the basic stuff set up but I know there is some minor tweaks. So this is what I have;

Code:
<html>

<head>

<script language="javascript">
//Main Function Caller
function caller() {

//Calling the findimage function
	alert(findimage());


//Start of the findimage function
function findimage() {
var images = document.getElementById("2");

//Start of the For Loop (findimage function)
	for(var counter = 0; counter < 6; counter++) {
		if(images[counter] == 2)
			{
			alert("Found Image #3.. It's source is: " + images.src);
			}
	}
//End of the For Loop (findimage function)

//Calling the findcontrol Function	
	alert(findcontrol());
}
//End of the findimage function


//Start of the findcontrol function
function findcontrol() {
var textform = document.myform;
var formlength = document.myform.length;

//Start of the For Loop (findcontrol function)
	for (var idform = 0; idform < formlength; idform++) {
		if(textform[idform].type=="text")
			{
			if (textform[idform].value=="")
				{
				alert("Sorry! You have not filled in number " + [idform] + " text field");
				}			
			}
			else 
				{
				alert("Thank you for filling everything in")
				}
			
	}
//End of the For Loop (findcontrol function)

//End of the findcontrol function
}

//End of the Caller function
}

</script>
</head>

<body>

<form name="myform">

<label>First Name</label><br /><input type="text" id="textone" />

<br />

<label>Last Name</label><br /><input type="text" id="texttwo" />

<br />

<label>Address</label><br /><input type="text" id="textthree" />

<br />

<label>Email Address</label><br /><input type="text" id="textfour" />


<p>
<img src="images/1.gif" id="0" />
<img src="images/2.gif" id="1" />
<img src="images/3.gif" id="2" />
<img src="images/4.gif" id="3" />
<img src="images/5.gif" id="4" />
</p>


<input type="button" value="Click Me" onclick="caller()" />
<input type="reset" value="Reset" />

</form>

</body>


</html>

03-07-2008, 05:48 PM
#2
hadriel is offline hadriel
hadriel's Avatar
Status: I'm new around here
Join date: Mar 2008
Location:
Expertise:
Software:
 
Posts: 22
iTrader: 0 / 0%
 

hadriel is on a distinguished road

  Old

Honestly, I don't like your code at all...

For the images function... You don't need loop, because you know the you need the image with Id==2

Anyway I did some changes, check if it works ok

Code:
<html>

<head>

<script language="javascript">
//Main Function Caller
function caller() {

//Calling the findimage function
	findimage();
findcontrol();
//End of the Caller function
}


//Start of the findimage function
function findimage() {
var images = document.getElementById("2");

//Start of the For Loop (findimage function)
	for(var counter = 0; counter < 5; counter++) {
		if(counter == 2)
			{ images = document.getElementById(counter);
			alert("Found Image #3.. It's source is: " + images.src);
			}
	}
//End of the For Loop (findimage function)

//Calling the findcontrol Function	
	
}
//End of the findimage function


//Start of the findcontrol function
function findcontrol() {
var textform = document.myform;
var formlength = document.myform.length;

//Start of the For Loop (findcontrol function)
	for (var idform = 0; idform < formlength; idform++) {
		if(textform[idform].type=="text")
			{
			if (textform[idform].value=="")
				{
				alert("Sorry! You have not filled in number " + [idform] + " text field");
				}			
			

				}
			
	}
//End of the For Loop (findcontrol function)

//End of the findcontrol function
}



</script>
</head>

<body>

<form name="myform">

<label>First Name</label><br /><input type="text" id="textone" />

<br />

<label>Last Name</label><br /><input type="text" id="texttwo" />

<br />

<label>Address</label><br /><input type="text" id="textthree" />

<br />

<label>Email Address</label><br /><input type="text" id="textfour" />


<p>
<img src="images/1.gif" id="0" />
<img src="images/2.gif" id="1" />
<img src="images/3.gif" id="2" />
<img src="images/4.gif" id="3" />
<img src="images/5.gif" id="4" />
</p>


<input type="button" value="Click Me" onclick="caller()" />
<input type="reset" value="Reset" />

</form>

</body>


</html>

Closed Thread    


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

  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