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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:43:16+00:00 2026-05-30T14:43:16+00:00

i have a HTML form, user should be able to add other text boxes

  • 0

i have a HTML form, user should be able to add other text boxes for a given question. but before any text input, there is a selection of dropdown menu, textboxes become visible after each selection(also depends on the selection, visible textbox count change). here is the javascript;

    var var1=1;
        function addAffiliation(){
                    var newArea = addNew();
                    var htcontents ="<input placeholder='categories..'  
class='input_box' type='textbox' name='categories[]' 
onchange='display(this, 'field2', 'field3', 'field4');'/>" 
                        + "<br/><br/>"; 
                    document.getElementById(newArea).innerHTML = htcontents;             
                }
        function addNew() {
                    var1=var1+1;       
                    var var2 = document.getElementById('area');
                    var newdiv = document.createElement('div');
                    var divIDName = 'Div #'+ var1;
                    newdiv.setAttribute('id',divIDName);
                    ni.appendChild(newdiv);
                    return divIDName;
               }

but when extra field is added, instead of;

<input placeholder="categories.."
    class="input_box" type="textbox" name="categories[]"
    onchange="display(this, 'field2', 'field3', 'field4');"/>

this is created (double quote location is wrong)

<input placeholder="categories.."  
        class="input_box' type="textbox" name="categories[]" 
        onchange="display(this, "field2', 'field3', 'field4');'/>

and because of that problem, field2-3-4 is not visible..

what to do?

here is the display function

function display(obj,id1,id2,id3) {
    txt = obj.options[obj.selectedIndex].value;
    document.getElementById(id1).style.display = 'none';
    document.getElementById(id2).style.display = 'none';
    document.getElementById(id3).style.display = 'none';
    if ( txt.match(id1) ) {
        document.getElementById(id1).style.display = 'block';
    }
    if ( txt.match(id2) ) {
        document.getElementById(id2).style.display = 'block';
    }
    if ( txt.match(id3) ) {
        document.getElementById(id3).style.display = 'block';
    }
}

@Aram,

I want to have a dropdown menu;

<option name="first">selection 1</option>
<option name="second">selection 2</option>

if user selects selection 1;

field1:< input name="field1".....>
field2:< input name="field2".....>

if user selects selection 1;

field3:< input name="field3".....>
field4:< input name="field4".....>
field5:< input name="field5".....>

when user finishes filling in the boxes, he might want to add more;

addReference();

then again he sees,

<option name="first">selection 1</option>
    <option name="second">selection 2</option>

and so on.. is that clear now?

  • 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-30T14:43:17+00:00Added an answer on May 30, 2026 at 2:43 pm

    solution came very close to what ManseUK suggested,

    var htcontents ="<input placeholder='categories..'  
    class='input_box' name='categories[]' 
    onchange='display(this, 'field2', 'field3', 'field4');'/>"
    

    should be

    var htcontents ="<input placeholder=\'categories..\'  //notice slashes
    class=\'input_box\' name=\'categories[]\' //notice slashes
    onchange=\'display(this, \'field2\', \'field3\', \'field4\');\'/>" //notice slashes
    

    hope that helps anyone..

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

Sidebar

Related Questions

I'm creating a form where the user should be able to enter any text
I have an HTML form where the user can type in any number:5, 8,
I'm building an HTML form with which the user should be able to upload
I'm trying to have the action of a HTML form built when the user
I have the following multi-select box in a HTML form, where user can select
I have an HTML page with a simple form. When the user clicks submit,
I have a form where a user selects a file, and then should be
I have an HTML form - with PHP, I am sending the data of
I have a HTML form, and I have a Controller Action that accepts the
I have an HTML form generated by JSF which maps an input element 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.