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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:53:08+00:00 2026-05-13T16:53:08+00:00

Ok, so this works perfectly well now however i’m reckoning it could be more

  • 0

Ok, so this works perfectly well now however i’m reckoning it could be more optomised as there is a lot of repeated code.

Anyone care to have a go?

var myObj = {
    gender:'',
    age:'',
    children:'',
    income:'',
    stage2select:'',
    day:'',
    spend:'',
    categories:'',
    product:'',
    price:'',
    quantity:'',
    total:''
};


$("#gender li").click(function() {
    myObj.gender = $(this).text();
    $('#age').show();
    update();
});
$("#age li").click(function() {
    myObj.age = $(this).text();
    $('#children').show();
    update();
});
$("#children li").click(function() {
  myObj.children = $(this).text();
    $('#income').show();
  update();
});
$("#income li").click(function() {
  myObj.income = $(this).text();
    $('#stage2select').show();
  update();
});

$("#stage2select :radio").change(function () {
    myObj.stage2select = $(this).val();
    if ( $(this).val() == 'shopping_patterns') {
            $('#day').show();
            $('#block3').hide();
            $('#block2').show();
    }
    if ( $(this).val() == 'specific_products') {
            $('#product').show();
            $('#block2').hide();
            $('#block3').show();
    }
  update();
});

$("#day li").click(function() {
  myObj.day = $(this).text();
    $('#spend').show();
  $("span.jquery_out").text(text);
});
$("#spend li").click(function() {
  myObj.spend = $(this).text();
    $('#categories').show();
  update();
});
$("#categories li").click(function() {
  myObj.categories = $(this).text();
    $('#total').show();
  update();
});
$("#product li").click(function() {
  myObj.product = $(this).text();
    $('#price').show();
  update();
});
$("#price li").click(function() {
  myObj.price = $(this).text();
    $('#quantity').show();
  update();
});
$("#quantity li").click(function() {
  myObj.quantity = $(this).text();
    $('#total').show();
  update();
});



function update() {
    var text = "";
    $.each(myObj, function(i){
        if (this != ''){
            if (text.length){
                text += " -> ";
            }
            text += this;
        }
    });
    $("span.jquery_out").text(text);
} 
  • 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-13T16:53:08+00:00Added an answer on May 13, 2026 at 4:53 pm

    There’s usually a way to repeat yourself less.

    var myObj = {
        gender:'',
        age:'',
        children:'',
        income:'',
        stage2select:'',
        day:'',
        spend:'',
        categories:'',
        product:'',
        price:'',
        quantity:'',
        total:''
    };
    var dependencies = [ 'gender', 'age', 'children', 'income', 'stage2select',
      'day', 'spend', 'categories', 'product', 'price', 'quantity', 'total'];
    var i;
    for (i = 1; i < dependencies.length; i++) {
        if (dependencies[i] != 'stage2select') {
            var prev = dependencies[i-1];
            var next = dependencies[i];
            (function(prev, next) {
                $("#" + prev + " li").click(function() {
                    myObj[prev] = $(this).text();
                    $('#' + next).show();
                    update();
                });
            })(prev, next);
        }
    }
    
    $("#stage2select :radio").change(function () {
        myObj.stage2select = $(this).val();
        if ( $(this).val() == 'shopping_patterns') {
                $('#day').show();
                $('#block3').hide();
                $('#block2').show();
        }
        if ( $(this).val() == 'specific_products') {
                $('#product').show();
                $('#block2').hide();
                $('#block3').show();
        }
      update();
    });
    
    function update() {
        var text = "";
        $.each(myObj, function(i){
            if (this != ''){
                if (text.length){
                    text += " -> ";
                }
                text += this;
            }
        });
        $("span.jquery_out").text(text);
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The CSS3 transition effect on this page works perfectly well on every other browser
This works perfectly if the priobann list is populated: banns << priobann?.pop() However, if
This works perfectly fine on localhost but doesn't work on my server, could anyone
This code works perfectly in Ubuntu, Windows, and Mac OS X. It also works
This code works perfectly except when you click on a link, The page is
This is my code that works perfectly to post one object to my server.
This works perfectly in Firefox but doesnt work in ie i get the following
I have been using Twitter's Bootstrap Tooltip plugin . This works perfectly fine except
I have a button which when toggled displays/hides a div ('.reportOptions'), this works perfectly
So I have this query that works perfectly: SELECT users.*, GROUP_CONCAT(categories.category_name) AS categories FROM

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.