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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:53:45+00:00 2026-06-11T23:53:45+00:00

I use a form that display some div depending on which option you click

  • 0

I use a form that display some div depending on which option you click of the radio button.

The thing is that the div is set to be none displayed, except if I select an option.

So I added the following function in order to make sure that if the div is displayed it will have th form havin the required property.

SO I give this function:

<script type="text/javascript">
function addattribute()
{
    if (document.getElementById('montant').style.display == "block")
    {
        document.getElementsByName('montant_creance').setAttribute('required');
        document.getElementsByName('condition2').setAttribute('required');
    }
    if (document.getElementById('montant').style.display == "none")
    {
        document.getElementsByName('montant_creance').setAttribute('required','false');
        document.getElementsByName('condition2').setAttribute('required','false');
    }
}
</script>   

But It say to me in the console:

Uncaught TypeError: Object #<NodeList> has no method 'setAttribute'

I really do not know how to find an issue.

Receive all my utmost Respect.

Kind Regards.

SP.

  • 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-11T23:53:46+00:00Added an answer on June 11, 2026 at 11:53 pm

    getElementsByName return a collection of elements, so you have to write e.g.

    document.getElementsByName('montant_creance')[0].setAttribute('required');
    

    every time you use this method (or similar methods, like getElementsByTagName, getElementsByClassName…) using the right index

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

Sidebar

Related Questions

I have two radio buttons on my MVC form that I use to hide
I have a form that I use to display several fields from a record
When i first load the page the flash container div is set to display:none,
So I have an unbound form that I use to save data to a
I have a user form that is working perfectly. The page makes use of
Our application used to make use of a common base form that all forms
I use a php form processor script that works fine. Except when users submit
I have an C# form application that use an access database. This application works
I have a small jQuery plugin that I use for form AJAX validation. There
I have an In-house windows form app that I would like to use Spell

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.