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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:48:38+00:00 2026-06-02T17:48:38+00:00

I am using the javascript code below to hide/how section based on project type

  • 0

I am using the javascript code below to hide/how section based on project type selected. The value in the array below is the value selected from a dropbox. The id below is the section/fieldset id [i know they are numeric, but that’s the way we got the app, so stuck with it right now]. I want to have multiple values like this:

value: “Ad”, value: “brochure”, value: “Bus wrap”

so basically I want to say: if value equals Ad or Brochure or Bus Wrap, display id 838. I can’t get this to work. How do I incorporate the “or” operator into this code?

//Project Types
var projectTypes = new Array (
    {id : '838', value: 'Ad'},
    {id : '838', value: 'Cars'},
    {id : '839', value: 'Brochure'},
    {id : '839', value: 'Planes'},
    {id : '840', value: 'Bus Wrap'},
    {id : '840', value: 'Boats'}
);

refreshSections(project_type);  

function refreshSections(selectedType) 
{   
    for (var i = 0; i < projectTypes.length; i++) 
    {
        if (projectTypes[i].value == selectedType) 
        {
            document.getElementById("section-"+ projectTypes[i].id).style.display = '';
        } 
        else 
        {
            document.getElementById("section-"+ projectTypes[i].id).style.display = 'none';
        }
    }
}

Here is an html sample of what I want to accomplish:

<head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
    <title>Project Overview</title>
    <script type="text/javascript">
    var projectType_Field_Id = '1169';

    //Project Types
    var projectTypes = new Array (
        {id : '11', value:'Cars'},
        {id : '12', value:'Boats'},
        {id : '13', value:'Planes'}

        );

    //occurs onLoad
    function formOnLoad()
    {
        var project_type = document.getElementById(projectType_Field_Id).value;
        refreshSections(project_type);
        }
    /*
     *  Onchange - Project Type
     */
    function projectTypeChange()
    { 
        var project_type = document.getElementById(projectType_Field_Id).value;
        refreshSections(project_type);
    }

    function refreshSections(selectedType) 
    {    
        for (var i = 0; i < projectTypes.length; i++) 
        {
            if (projectTypes[i].value == selectedType) 
            {
                document.getElementById("section-"+ projectTypes[i].id).style.display = '';
            } else {
                document.getElementById("section-"+ projectTypes[i].id).style.display = 'none';
            }
        }

    }


    </script>
    </head>

    <body onload="formOnLoad();">
    <form method="post" action="">
    <fieldset name="mainSection">
                    <legend style="color:blue; font-weight:bold">Project Overview Section</legend>

                    <table style="width: 100%">
                        <tr>
                            <td style="height: 33px; width: 178px; color:maroon">Name</td>
                            <td style="height: 33px"><input  id="1125" name="1125" type="text" /></td>
                        </tr>
                        <tr>
                            <td style="height: 33px; width: 178px; color:maroon">Email</td>
                            <td style="height: 33px"><input  id="1026" name="1026" type="text" /></td>
                        </tr>
                        <tr>
                            <td style="width: 178px">Product Title</td>
                            <td><input  id="1089" name="1089" type="text" /></td>
                        </tr>
                        <tr>
                            <td style="width: 178px">Product Type</td>
                            <td><select id="1169" name="1169"  onChange="projectTypeChange();">
                            <option value="">Select</option>
                            <option value="Cars">Cars</option>
                            <option value="Boats">Boats</option>
                            <option value="Planes">Planes</option>
                            <option value="Trains">Trains</option>
                            <option value="Skateboard">Skateboard</option>
                            <option value="Helicopter">Helicopter</option>

                            </select></td>
                        </tr>
                                        </table>
                </fieldset><br /><br />

                <fieldset id="section-11" name="section-11">
                    <legend style="color:fuchsia; font-weight:bold">Car Details Section</legend>

                    <table cellpadding="2" style="width: 100%">
                        <tr>
                            <td style="width: 334px; height: 35px"><label style="color:maroon">Size:</label></td>
                            <td style="height: 35px"><input id="1245" name="1245" type="text" /></td>
                        </tr>
                        <tr>
                            <td style="height: 35px; width: 334px">Color:</td>
                            <td style="height: 35px">
                            <select id="1433" name="1433">
                    <option value="Orange">Orange</option>
                            <option value="Blank">Blank</option>
                            <option value="Green">Green</option>
                </select></td>
                        </tr>
                        <tr>
                            <td style="width: 334px">Description:</td>
                            <td>
                            <textarea id="1290" name="1290" rows="2" style="width: 433px"></textarea></td>
                        </tr>
                    </table>
                                </fieldset>
                                <br />
                <fieldset id="section-12" name="section-12">
                    <legend style="color:fuchsia; font-weight:bold">Plane Details Section</legend>

                    <table cellpadding="2" style="width: 100%">
                        <tr>
                            <td style="width: 334px; height: 35px"><label  style="color:maroon">Size:</label></td>
                            <td style="height: 35px"><input id="1245" name="1245" type="text" /></td>
                        </tr>
                        <tr>
                            <td style="height: 35px; width: 334px">Color:</td>
                            <td style="height: 35px">
                            <select id="1433" name="1433">
                    <option value="Orange">Orange</option>
                            <option value="Blank">Blank</option>
                            <option value="Green">Green</option>
                </select></td>
                        </tr>
                        <tr>
                            <td style="width: 334px">Description:</td>
                            <td>
                            <textarea id="1290" name="1290" rows="2" style="width: 433px"></textarea></td>
                        </tr>
                    </table>
                                </fieldset><br />
                <fieldset id="section-13" name="section-13">
                    <legend style="color:fuchsia; font-weight:bold">Boat Details Section</legend>

                    <table cellpadding="2" style="width: 100%">
                        <tr>
                            <td style="width: 334px; height: 35px"><label  style="color:maroon">Size:</label></td>
                            <td style="height: 35px"><input id="1245" name="1245" type="text" /></td>
                        </tr>
                        <tr>
                            <td style="height: 35px; width: 334px">Color:</td>
                            <td style="height: 35px">
                            <select id="1433" name="1433">
                    <option value="Orange">Orange</option>
                            <option value="Blank">Blank</option>
                            <option value="Green">Green</option>
                </select></td>
                        </tr>
                        <tr>
                            <td style="width: 334px">Description:</td>
                            <td>
                            <textarea id="1290" name="1290" rows="2" style="width: 433px"></textarea></td>
                        </tr>
                    </table>
                                </fieldset>
    <fieldset id="section-1011" name="section-1011">
                    <legend style="color:green; font-weight:bold">Misc Info Section</legend>

                    <table cellpadding="2" style="width: 100%">
                        <tr>
                            <td style="width: 334px; height: 35px"><label>Size:</label></td>
                            <td style="height: 35px"><input id="1301" name="1301" type="text" /></td>
                        </tr>
                        <tr>
                            <td style="height: 35px; width: 334px">Color:</td>
                            <td style="height: 35px">
                            <select id="1302" name="1302">
                    <option value="Orange">Orange</option>
                            <option value="Blank">Blank</option>
                            <option value="Green">Green</option>
                </select></td>
                        </tr>
                        <tr>
                            <td style="width: 334px">Description:</td>
                            <td>
                            <textarea id="1303" name="1303" rows="2" style="width: 433px"></textarea></td>
                        </tr>
                    </table>
                                </fieldset>
                                <input name="Send Job" type="submit" value="Send Job" />

    </form>
  • 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-02T17:48:42+00:00Added an answer on June 2, 2026 at 5:48 pm

    It looks like in your for loop, you only need to check if your selectedType matches one of the projectTypes. Try this –

    for (var i = 0; i < projectTypes.length; i++) 
    {
        if (projectTypes[i].value == selectedType) 
        {
            document.getElementById("section-"+ projectTypes[i].id).style.display = '';
            break;
        } 
    
    }
    

    This will only show your element when it matches a project type, and then break out of the loop right after matching.

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

Sidebar

Related Questions

I'm using the following JavaScript code: <script language=JavaScript1.2 type=text/javascript> function CreateBookmarkLink(title, url) { if
I am using the code below to show and hide a div called map
Below is le code. I want movementCanvas underneath canvas. <html> <head> <script type=text/javascript src=game.js></script>
Im using the below code of ajax // JavaScript Document function createTeam() { var
I'm trying to find URLs in some text, using javascript code. The problem is,
I am currently using a javascript code to make an entire row in my
I currently am using this JavaScript code snippet to select 3 checkboxes at a
I am using the following JavaScript code: var a = [23, 34, 45, 33];
I'm using the javascript ticker code found here . In Chrome and Safari, the
I have a javascript code using which I want to accomplish the following .

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.