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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T16:17:25+00:00 2026-05-21T16:17:25+00:00

I have a form which I am using to update an existing set of

  • 0

I have a form which I am using to update an existing set of information in a database. Within it is a selection box, when option ‘B’ is chosen it shows a hidden section, and on option ‘A’ it will hide the section. This works fine.

However, when I load a record set from the database and the selection box is set to option ‘B’ to show the hidden div, it is not shown.

This is because I’m switching the DIV tag using ‘onchange’.

How do I get the JS to show the DIV tag correctly onload of the record set? Currently to see the data I have to toggle the selection box between the two options.

I know next to nothing about JS, the JS below isn’t mine, I’d appreciate some help.

Thanks

<!--- show / hide DIV based on select --->

<script type="text/javascript"><!--
var lastDiv = "";
function showDiv(divName) {
    // hide last div
    if (lastDiv) {
        document.getElementById(lastDiv).className = "hiddenDiv";
    }
    //if value of the box is not nothing and an object with that name exists, then change the class
    if (divName && document.getElementById(divName)) {
        document.getElementById(divName).className = "visibleDiv";
        lastDiv = divName;
    }
}
//-->
</script>
<style type="text/css" media="screen"><!--
.hiddenDiv {
    display: none;
    }
.visibleDiv {
    display: block;
    border: 0px grey solid;
    }

--></style>
<!--- end DIV hide --->



--------------snip----------



  <select name="ad_i" id="ad_i" onchange="showDiv(this.value);">
      <option value="in" <? echo $adtypea; ?> >Option A </option>
      <option value="ba" <? echo $adtypeb; ?> >Option B</option>
   </select>

   <!--- start hiding DIV --->

  <div class="hiddenDiv" id="ba">

  <br /><br />Coding for Ad<br />

<select name="ad_type" id="ad_type">
      <option value="html" <? echo $codestylea; ?> >HTML</option>
      <option value="adsense"<? echo $codestylef; ?>>Adsense / Other JavaScript Code</option>
      <option value="img" default="default" <? echo $codestyleb; ?>>Image</option>
      <option value="swf" <? echo $codestylec; ?>>Flash</option>
   </select>


   </div>
   <!--- end Div for hidden--->
  • 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-21T16:17:25+00:00Added an answer on May 21, 2026 at 4:17 pm

    After you’ve rendered the select box and the div’s you want to show/hide call:

    <script type="text/javascript">
    var selectbox = document.getElementById("ad_i");
    showDiv(selectbox.options[selectbox.selectedIndex].value);
    </script>
    

    so I think it should go after

    <!--- end Div for hidden--->
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing a site using the CakePHP framework. I have a form which shows
I have a form MyForm which I update using ajax as the user fills
I have this form which can insert/update values into database table. <div id=settingsdiv style=width:350px;
I have a field in my update form called approve which is using the
I have a form which binds a model and a file upload using the
I have several DropDown controls on a Web Form which are filled using AJAX
I have a webpage with a form, which looks kinda like this: @using (Html.BeginForm(MyAction,
I am creating one form in html using table. Which have one Drop down
I am using ASP.NET MVC 1.0. I have an ActionResult which receives a form
Im using c# .net , windows form application. I have a XML file which

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.