Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6636661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:12:50+00:00 2026-05-25T23:12:50+00:00

I am getting some values from server in XML format using ajax. The format

  • 0

I am getting some values from server in XML format using ajax. The format is like :

<employees><employee><id>Id</id><employeeName>Name</employeeName></employee>.....</employees>

So to process this response i use

 if(employees.childNodes.length>0){
                    for (loop = 0; loop <     employees.childNodes.length; loop++) {
                     var employee = employees.childNodes[loop];
                     var ids = employee.getElementsByTagName("id")[0].childNodes[0].nodeValue;
                     var name = employee.getElementsByTagName("employeeName")[0].childNodes[0].nodeValue;
                     s=s+'<input name=\"userAction'+type+'\" id=\"userAction'+type+'\" value=\"'+ids+'\" type=\"checkbox"\/>'+name+'<br\/>';            


                   }
                                       document.getElementById('div'+type).innerHTML=s;                        
}

I am able to successfully show the no. of users in . But my problem is when i click on submit function i want to know the length of no. of chekboxes. As u see i use the same name of all the checkoxes in a particular div.

var lennt=document.frm["userAction"+i].length;
                alert(lennt)

If there were more than 1 user the lenght is ok, but for one user it is giving me “undefined”
Please help me…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T23:12:51+00:00Added an answer on May 25, 2026 at 11:12 pm

    The problem you have is if there are no elements named "userAction"+i then document.frm["userAction"+i] is undefined, if there is only 1 then document.frm["userAction"+i] is a reference to one DOM node so there is no length property, if there are > 1, document.frm["userAction"+i] is a reference to a DOMNodeList, so there IS a length property. Solution: do some tests like so:

    var checkboxes = document.frm["userAction"+i];
    var lennt = 0; // default
    if (checkboxes) { // checkboxes is not undefined
        // assign value based on whether checkboxes.length is defined
        lennt = (checkboxes.length) ? checkboxes.length : 1;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my application, I am getting some string values from a server, but I'm
I am storing some values that I am getting from server in the database
So I've been getting some mysterious uninitialized values message from valgrind and it's been
I am getting some response from server side which i need to parse but
When getting values out of xml attributes, using the xquery value operator, missing attributes
Using MS SQL Server, I've got some data in an XML field (called XML
I'm having a bit of an issue. I am getting some values from my
my script is getting some array from php server side script. result = jQuery.parseJSON(result);
i'm writing some code for getting some values including course -(void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation
I have a data table which already has some values, plus it is getting

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.