SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict dr_dumb99's Avatar
    Join Date
    Sep 2004
    Location
    Pakistan
    Posts
    304
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Form input elements length individually

    Hi!
    How can I get total number of checkboxes/input boxes/radio buttons/ combo boxes/ list boxes? I want to get individual total of each of these form elements?

    Thanks in advance

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    var inp = document.getElementsByTagName("input");
    for(var i = 0; i < inp.length; i++) {
    if(inp[i].type == "text") alert(inp[i].length + " text fields present");
    if(inp[i].type == "file") alert(inp[i].length + " file fields present");
    if(inp[i].type == "radio") alert(inp[i].length + " radio buttons present");
    if(inp[i].type == "checkbox") alert(inp[i].length + " checkboxes present");
    }
    
    var sel = document.getElementByTagName("select");
    alert(sel.length + " dropdown lists present"); 
    
    
    var txtArea= document.getElementByTagName("textarea");
    alert(txtAreaa.length + " textareas present");
    cheers


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •