Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 10th, 2005, 12:19 PM
Authorized User
 
Join Date: Sep 2004
Posts: 68
Thanks: 1
Thanked 0 Times in 0 Posts
Default Checkboxes--number written to screen

Good morning.

I have a program in which I write various numbers of checkboxes to the user's screen. The number of checkboxes written varies depending on the content written from the database. The form will have all sorts of items written to it: checkboxes, dropdown lists, text boxes, etc.

Is there a way in JavaScript to "count" the total number of checkboxes written to the screen? I need to loop through all of the checkboxes that I write to the screen.

Thank you!

Sal
 
Old January 10th, 2005, 12:40 PM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

No direct way but:
Code:
function getInputsByType(Type)
{
  var colInputs = document.getElementsByTagName("input");
  var arrTargets = new Array():
  var sType = Type.toLowerCase();
  for (var i = 0; i < colInputs.length; i++)
  {
    var oInput = colInputs[i];
    if (oInput.type.toLowerCase() == sType)
    {
      arrTargets.push(oInput);
    }
  }
  return arrTargets;
}
then
Code:
 var arrCheckboxes = getInputsByType("checkbox")
or
Code:
var arrTextboxes = getInputsByType("text")

--

Joe (Microsoft MVP - XML)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Can a program be written so that? Joe Gelso Other Programming Languages 1 November 8th, 2007 10:13 PM
arabic language written from left to right !!! seco Dreamweaver (all versions) 0 April 3rd, 2007 01:58 PM
What langauge was this app written in? flavour404 Other Programming Languages 14 March 8th, 2007 11:37 AM
Draw on the screen without clearing the screen pu132 Visual Basic 2005 Basics 0 August 25th, 2006 09:03 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.