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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:25:40+00:00 2026-05-19T12:25:40+00:00

I have a javascript function I wrote to append a select box to a

  • 0

I have a javascript function I wrote to append a select box to a radiobutton set based on which radio button is clicked. It does this when one clicks one or the other. The problem is, I’m such an amateur that I can’t get it to stop adding new select elements to the span I set to place them in. I keep trying different ways to check if the element or its innerHtml have been set and then use that check to decide whether to create another select. None of this has worked for me. Can anyone point me in the direction of a tutorial for this (i’ve been searching, tried nearly everything, no fez which makes me think its a simpler problem with the structure of the whole function).

Here is the code, any light shed on this would be SUPER helpful. I just taught myself to code so I know this is horrible. Thanks for the help!!

function moreInput(vInput)  {
var moreD = document.getElementById('moreD');
//document.write(moreD);
    if(vInput == \"approved\")  {
        if(moreD.length > 0)    {
            moreD.removeChild(approvedOpts);
        }
        var select = document.createElement(\"select\");
        select.options[0] = new Option('a');
        select.options[1] = new Option('b');
        select.options[2] = new Option('c');
        select.setAttribute(\"name\",\"approvedOptsA\");
    }
    if(vInput == \"denied\")    {
        //alert(moreD.innerHtml);
        //if(moreD.innerHtml === 'undefined')   {
            //moreD.removeChild(approvedOptsD);
            var select = document.createElement(\"select\");
            select.options[0] = new Option('x');
            select.options[1] = new Option('y');
            select.options[2] = new Option('z');
            select.setAttribute(\"id\",\"approvedOptsD\");
            select.
        //}
    }
moreD.appendChild(select);

}

  • 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-19T12:25:41+00:00Added an answer on May 19, 2026 at 12:25 pm

    Remove all elements before you add any new elements.

    This code should work:

    <script type=\"text/javascript\">
    
    function moreInput(vInput)  {
        var moreD = document.getElementById('moreD');
            if(vInput == \"approved\")  {
                removeAllChildrens(moreD);
                var select = document.createElement(\"select\");
                select.options[0] = new Option('Comped Table');
                select.options[1] = new Option('Comped Drink');
                select.options[2] = new Option('Comped Cover');
                select.setAttribute(\"name\",\"approvedOptsA\");
            }
            if(vInput == \"denied\")    {
                    removeAllChildrens(moreD);
                    var select = document.createElement(\"select\");
                    select.options[0] = new Option('Need to Reserve Table');
                    select.options[1] = new Option('At Capacity');
                    select.options[2] = new Option('Private Event');
                    select.setAttribute(\"id\",\"approvedOptsD\");
            }
        moreD.appendChild(select);
    }
    
    function removeAllChildrens(cell) {
        if ( cell.hasChildNodes() ) {
            while ( cell.childNodes.length >= 1 ) {
                cell.removeChild( cell.firstChild );       
            } 
        }
    }
    
     </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a JavaScript function named move which does just windows.location.href = any given
I have a little javascript function which is attached to an onClick event of
I have a javascript function that manipulates the DOM when it is called (adds
I have a JavaScript function, pop_item . I have to call this from PHP,
I have a javascript function (class) that takes a function reference as one paremter.
I have a javascript function (function1) that checks some global variables (can the user
I have Designed the Javascript function My.js it contains following code My.js function display(){
I want to call a c# function from my javascript function. I have a
Modern browsers have multi-tab interface, but JavaScript function window.showModalDialog() creates a modal dialog that
I have an external JavaScript that contains: function random_imglink(){ var myimages=new Array() myimages[1]="http://sevir.sitegoz.com/jchs/Banner1.png" myimages[2]="http://sevir.sitegoz.com/jchs/banner2.png"

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.