473,569 Members | 2,466 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

JavaScript to hide a <div> via checkbox that is already checked

19 New Member
I have a web site that uses the following JavaScript to hide <div> sections:

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. function showMe (it, box) {
  3. var vis = (box.checked) ? "block" : "none";
  4. document.getElementById(it).style.display = vis;
  5. }
  6. </script>
  7.  
I have a checkbox to hide the <div> when checked:

[HTML]<input type="checkbox" name="multi_not e" value="Yes" onclick="showMe ('div1', this)">
[/HTML]
This works great if I load the page without the checkbox being checked. When I check the box, the <div1> appears. But I need the checkbox to be checked when the person first visits the site, and when they click OFF the checkbox, it needs to hide <div1>.

I know that it is probably simple, but I can't seem to figure it out...

Thanks - Tony
Oct 3 '07 #1
5 4896
dmjpro
2,476 Top Contributor
I have a web site that uses the following JavaScript to hide <div> sections:
Expand|Select|Wrap|Line Numbers
  1. function showMe (it, box) {
  2. var vis = (box.checked) ? "block" : "none";
  3. document.getElementById(it).style.display = vis;
  4. }
  5.  
I have a checkbox to hide the <div> when checked:
Expand|Select|Wrap|Line Numbers
  1. <input type="checkbox" name="multi_note" value="Yes" onclick="showMe('div1', this)">
  2.  
This works great if I load the page without the checkbox being checked. When I check the box, the <div1> appears. But I need the checkbox to be checked when the person first visits the site, and when they click OFF the checkbox, it needs to hide <div1>.

I know that it is probably simple, but I can't seem to figure it out...

Thanks - Tony

Use code Tags while you do post some codes.
Simply have this :-)

Expand|Select|Wrap|Line Numbers
  1. <input type="checkbox" name="multi_note" value="Yes" onclick="showMe('div1', this)" checked>
  2.  
Kind regards,
Dmjpro.
Oct 3 '07 #2
widevision7
19 New Member
I have already tried adding the checked tag, as in:

<input type="checkbox" name="multi_not e" value="Yes" onclick="showMe ('div1', this)" checked>

and when I load the page, it shows that the checkbox is checked, but the <div1> is hidden. I need for the checkbox to be checked and for the <div1> to be visible.

When they uncheck the checkbox, then the <div1> will be hidden.

Thanks - Tony
Oct 3 '07 #3
acoder
16,027 Recognized Expert Moderator MVP
In your div, just add a style of display set to 'block':
[HTML]<div id="div1" style="display: block;">[/HTML]
Oct 3 '07 #4
widevision7
19 New Member
THANKS!!! That worked!

Tony
Oct 4 '07 #5
acoder
16,027 Recognized Expert Moderator MVP
Glad to hear you got it working. Post again if you any more questions.
Oct 4 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

7
2106
by: F. Da Costa | last post by:
Hi, I' looking to retrieve ProdName1 form the <tr> below. <tr id="1-1-1" class="even"> <td> <div class="tier4"> <a href="#" class="leaf"></a> ProdName1 </div>
19
4443
by: benzwt | last post by:
I use the following function to hide a <div> named one. function hideObject() { if (ns4) { document.n1.visibility = "hide"; } else if (ie4) { document.all.style.visibility = "hidden"; } else if (nn6) {
2
12179
by: MOHSEN KASHANI | last post by:
Hi, I am trying to hide some form elements in a form by default and show/hide depending on which radio button is clicked. This is what I have but it is not working: <head> <style> ..noshow { display: none; }
2
2093
by: Ruskin Hardie | last post by:
There is an iframe in my document that is hidden, which is the target for a submitted form. When the form is submitted, some javascript sets a hidden div, to displaying, eg: document.getElementById('hiddendiv').style.display = ''; This div, simply has the words "building csv file, please wait", and is used, because their is no indication...
6
5093
by: cargo303 | last post by:
I have a php page with a drop down list, and the default selected option is "Select a location" (without quotes). Using the drop down initiates a database query. One of (3) things should happen: 1. If an option is selected for which results are available, they should be displayed on the same page beneath the drop down list in a table....
2
2504
by: shivendravikramsingh | last post by:
hello friend,i m using this code<div id="get" style="visibility:hidden"><? include "time_title.php" ?></div> in a php page,i want when page load the inclued page time_tiltle.php should not shown,when i click a button,it should appear.but i don't no wat.s the prob. when i open the page it showing the content of timr_title.php,the <div> visibility...
1
2320
by: widevision7 | last post by:
I have a web page that uses the following JavaScript to hide a <div> unless the checkbox is checked: <script type="text/javascript"> function showMe (it, box) { var vis = (box.checked) ? "block" : "none\ document.getElementById(it).style.display = vis; } I need to have it where if the box is not checked with 10 seconds, then a <meta...
1
3306
by: Window Frog | last post by:
Hello all, I am going to be utilizing a <divon a site that is shown and hidden w/ the click of a button. I can already do this, but when the button is clicked the <divis show quite rapidly. I'd like to slow the opening/showing process with something emulating a motion tween. Apple uses something like this in their menus on their website. Any...
8
10024
prino
by: prino | last post by:
Hi all, I've written code (in REXX) that takes files in legacy languages (PL/I, COBOL, z/OS assembler, etc) and converts them into HTML in a format similar to what's displayed in the z/OS ISPF editor. A fellow member of the PCG has helped me by creating a bit of Javascript to emulate the scrolling and using Google I've now gotten it into a...
0
7618
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7926
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7982
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6286
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5222
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3644
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1226
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
944
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.