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 255913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:58:13+00:00 2026-05-11T21:58:13+00:00

This is surely a JS beginner question. My issue is I want to use

  • 0

This is surely a JS beginner question.

My issue is I want to use the value of the variable type to access the relevant checkbox; however it is treating the variable as a string. I have tried it to two ways.

function toggleGroup(type) {
    if (document.getElementById(type).checked == true){
        alert("foo");
    }
}

or

function toggleGroup(type) {
    if (document.nav.type.checked == true){
        alert("foo");           
    }
}
  • 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-11T21:58:13+00:00Added an answer on May 11, 2026 at 9:58 pm

    We have no way of knowing how type should be treated – you haven’t show us how the function is being called (in particular, we don’t know what you are passing as its argument).

    If it is a string (matching the id of an element), than document.getElementById(type).checked should work (although == true is redundant).

    document.nav.type.checked should not work, because dot-notation property names are not interpolated. You have to use square bracket notation for that: document.forms.nav.elements[type].checked. This will match on name or id – if you have multiple elements with the same name, then document.forms.nav.elements[type] will be an object you can treat as an array (and won’t have a checked property).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use a temp directory that will be unique to this build.
This surely is a noob question, but I can't find an answer in Doxygen
This is surely obvious but I'm stuck on it. I want to have something
this is surely a basic question for most of you but it still giving
This is a rather broad question, but I'm a beginner-intermediate programmer that has just
This is surely a basic question, but I'm new enough to MVC (and ASP.NET)
Surely this is a newb question as I am just learning RoR and can't
Surely this is possible? I have been hunting through PyQt tutorials and documentation but
Surely there is some kind of abstraction that allows for this? This is essentially
Surely there is a better way to do this? results = [] if not

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.