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

  • Home
  • SEARCH
  • 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 8106485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:28:55+00:00 2026-06-06T00:28:55+00:00

Total noob here with javascript. I’m trying to alter a function. This is the

  • 0

Total noob here with javascript. I’m trying to alter a function. This is the one that is currently there and works.

function hideStateField(theForm) {
    theForm.state.disabled = true;
    theForm.state.className = 'hiddenField';
    theForm.state.setAttribute('className', 'hiddenField');
    document.getElementById("stateLabel").className = 'hiddenField';
    document.getElementById("stateLabel").setAttribute('className', 'hiddenField');
    document.getElementById("stateText").className = 'hiddenField';
    document.getElementById("stateText").setAttribute('className', 'hiddenField');
    document.getElementById("stateBreak").className = 'hiddenField';
    document.getElementById("stateBreak").setAttribute('className', 'hiddenField');
}

I want to make it more generic so its not specific to the “state” field. So I’m changing the function name to reflect that and adding a 2nd parameter. Then I’m trying to use that 2nd parameter as a variable in place of where we see “state”.

function hideAddressField(theForm,theField) {
    theForm.theField.disabled = true;
    theForm.theField.className = 'hiddenField';
    theForm.theField.setAttribute('className', 'hiddenField');
    document.getElementById(theField+"Label").className = 'hiddenField';
    document.getElementById(theField+"Label").setAttribute('className', 'hiddenField');
    document.getElementById(theField+"Text").className = 'hiddenField';
    document.getElementById(theField+"Text").setAttribute('className', 'hiddenField');
    document.getElementById(theField+"Break").className = 'hiddenField';
    document.getElementById(theField+"Break").setAttribute('className', 'hiddenField');
}

I tested it simply with “state” as the 2nd variable to be sure it worked… and it didn’t. I keep getting “Uncaught TypeError: Cannot set property ‘disabled’ of undefined”. I’m sure its a syntax error. My call to this function is:

hideAddressField(theForm,state);

The form’s name is “theForm” as well so I figured the variable “theForm” was being assigned a value of “theForm” while the variable “theField” was being assigned the value of “state” and the two functions should be equivelant. Obviously not.

Where am I going wrong?

  • 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-06-06T00:28:56+00:00Added an answer on June 6, 2026 at 12:28 am

    You must use theForm[theField] syntax, because “theField” is a variable containing the name of a property, and is not the property itself. Also, you will need to pass state as a string.

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

Sidebar

Related Questions

Total noob here. This is my first c# attempt, its a console application that
First timer here, and total noob when it comes to PHP and JavaScript. I
Hey! Total CakePHP noob here. Updated at bottom / This is sort of a
Total Haskell noob here. I have a simple function, and a main. I don't
Total noob question, but here. CSS .product__specfield_8_arrow { /*background-image:url(../../upload/orng_bg_arrow.png); background-repeat:no-repeat;*/ background-color:#fc0; width:50px !important; height:33px
I'm a total noob trying to create a website with PHP. I created a
I'm a total noob when it comes to C but i found this curl
Total noob question here, but not finding the answer via search. What is the
well...just about all I needed to say...lookie here, I'm a total noob in web
I'm a total noob when it comes to jQuery but I am trying to

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.