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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:04:49+00:00 2026-05-31T01:04:49+00:00

For each user, there are several references. Each reference might have different attributes. So

  • 0

For each user, there are several references. Each reference might have different attributes. So I want the user to select the reference attribute first, then for that attribute input fields become visible. If a user has multiple references, he might be able to add a new reference by simply clicking the add button and a new selection appears, and so on.

I tried to do it with javascript but there was some minor problems. I found a rather simple jQuery solution for handling selection:

HTML

<form>
    <select id="sel">
        <option value="">- select -</option>
        <option value="option1">Option 1</option>
        <option value="option2">Option 2</option>          
    </select>
    <input type="text" class="option1" /><span>Textbox label 1</span>
    <input type="text" class="option2" /><span>Textbox label 2</span>
    <input type="text" class="option2" /><span>Textbox label 2</span>
    <input type="text" class="option2" /><span>Textbox label 2</span>
</form>

jQuery

$(function() {
    $('#sel').change(function() {
        $("input").hide().filter("." + $(this).find("option:selected").val()).show();
    });
    $("input").focus(function() {
        $(this).next("span").fadeIn(1000);
    }).blur(function() {
        $(this).next("span").fadeOut(1000);
    });
});

CSS

input {
    display:none;
}
span {
    display:none;
}

and then adding new divs..

var inival=1;
function addNew(){
    var newArea = add_New_Element();
    var htcontents = "<select id="sel">"+
        "<option value="">- select -</option>"+
        "<option value="option1">Option 1</option>"+
        "<option value="option2">Option 2</option>"  +        
    "</select>"+
    "<input type="text" class="option1" /><span>Textbox label 1</span>"+
    "<input type="text" class="option2" /><span>Textbox label 2</span>"+
    "<input type="text" class="option2" /><span>Textbox label 2</span>"+
    "<input type="text" class="option2" /><span>Textbox label 2</span>"; 
    document.getElementById(newArea).innerHTML = htcontents;            
}

function add_New_Element() {
    inival=inival+1; 
    var ni = document.getElementById('area');
    var newdiv = document.createElement('div'); 
    var divIdName = 'Div #'+ inival;
    newdiv.setAttribute('id',divIdName);
    ni.appendChild(newdiv);
    return divIdName;
}

function addNew();

But you might see, this is a very long solution. I guess there is more efficient and shorter solutions. Any help is much appreciated.

  • 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-31T01:04:50+00:00Added an answer on May 31, 2026 at 1:04 am

    Although it is not my solution, it might help other people

    http://jsfiddle.net/MXXXT/16/

    original answer is belonging to Jeff

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

Sidebar

Related Questions

There are several packages in my application that user can select each one according
I have user generated podcasts, each with their own RSS feed. Is there a
I have a table with user items. Each user may have several types of
Is it better to have a different CSS file for each user-agent or is
This first script gets called several times for each user via an AJAX request.
For each user, I want to allow them to choose their preferences, such as
I have a rails application where each user has a separate database. (taking Joel
I have article table and several user tables a_user , b_user , ... with
So I have an application that has several modules (think of modules as different
I have a rails 3.1 project using devise for authentication. I have several user

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.