Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



JavaScript to count number of images

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 11-12-2009
Member
 
Join Date: Nov 2009
Posts: 75
JavaScript to count number of images
  

I have certain queries in my JavaScript project. There will be multiple images on my form. These will be selected by the user on the form prior to this form. When the user comes on this form of images it should display how many images are present in the current form. So the user is not needed to count his/her selection. I am unable to code this.

Reply With Quote
  #2  
Old 11-12-2009
Member
 
Join Date: Oct 2005
Posts: 2,387
Re: JavaScript to count number of images

Images Object Array is supported in JavaScript 1.1 version of JavaScript. The Image Object Array is a collection of all the images in a document. To determine the total number of images displayed in the document we need to use the length property. Thus if you need to count the number of images using JavaScript use the length property of Image Object Array.
Reply With Quote
  #3  
Old 11-12-2009
Member
 
Join Date: Apr 2008
Posts: 1,997
Image Object for Images

In JavaScript we can deal with images in a document using JavaScript Image Object. The basic syntax to access the image using the image object is:
To access image relative to its location in an array:
Quote:
document.images[i]
Using Image name to access the image:
Quote:
document.images.name
To get the image count
Quote:
document.images.length
Reply With Quote
  #4  
Old 11-12-2009
Member
 
Join Date: Apr 2008
Posts: 1,946
document.images.length to count image

I too had to keep a track of the image count in my JScript project where the images resembled the choices made by the visitor and I had to tally them all at the end. I tried many things and finally this piece of code helped me to get the image count:
Code:
<script language="JavaScript1.1">
    document.write(document.images.length);
</script>
Include the above code in your project to enable image count in a document. You may print or save the image count to be used later.
Reply With Quote
  #5  
Old 11-12-2009
Member
 
Join Date: Feb 2008
Posts: 1,843
JavaScript for HTML

Code:
<html>
<B>Tiger</B>
    <img src="Tiger.gif">
<br>

<B>Cat</B>
    <img src="Cat.gif">
<br>

<B>Lion</B>
    <img src="Lion.gif">
<br>

<script language="JavaScript">
    <!--
    document.write(document.images.length," Images");
    -->
</script>
</html>
This piece of code helped me to track the number of images in my file using the scripting language as JavaScript with HTML web page. Hope this will work for you as well.
Reply With Quote
  #6  
Old 11-12-2009
Member
 
Join Date: May 2008
Posts: 2,376
counting images in JavaScript

I had an assignment question where in it was required to a count of images on a web page which was to be scripted using JavaScript. We were given two images on a document and had to count them to display the image count as 2. This is the program that I did:
Code:
<html>
<body>
<img alt="Virus" border="0" src="Pic1.gif" width="70" height="70" />
<br />
<img alt="Worm" border="0" src="Pic2.gif" width="50" height="50" />
<br /><br />

<script type="text/javascript">
document.write("The image count of this document is: " + document.images.length);
</script>

</body>
</html>
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "JavaScript to count number of images"
Thread Thread Starter Forum Replies Last Post
How to count number of characters in Excel Bankebihari Windows Software 6 15-05-2012 04:52 PM
PHP - Count number of words GlassFish Software Development 3 27-11-2009 12:19 PM
Count the number of times yes appears in a range in excel Andy Candy Windows Software 3 17-08-2009 12:33 PM
How to count number of words automatically? Basaam Windows Software 4 25-04-2009 10:00 PM
How To Count The Number Of Characters? Harsh01 Software Development 2 13-02-2009 11:25 AM


All times are GMT +5.5. The time now is 06:37 AM.