Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

my javascript on load if select box checked

Posted on 2011-09-17
4
Medium Priority
?
232 Views
Last Modified: 2012-05-12
Hello,

I need sections of my page visible on load, if the corresponding checkbox is selected. My javascript file currently looks like --

window.onload = function resettoggle() {
var e = document.getElementById('ULSpecialDescriptionTGI');
e.style.display = 'none';
var e = document.getElementById('ULSpecialDescriptionPro');
e.style.display = 'none';
var e = document.getElementById('Pro-Direct-Special-Header');
e.style.display = 'none';
var e = document.getElementById('TGI-Direct-Special-Header');
e.style.display = 'none';

var e = document.getElementById('TGI-Direct-Pricing-Wrapper');
e.style.display = 'none';
var e = document.getElementById('TGI-Direct-Carriage-Wrapper');
e.style.display = 'none';
var e = document.getElementById('PRO-Direct-Pricing-Wrapper');
e.style.display = 'none';
var e = document.getElementById('PRO-Direct-Carriage-Wrapper');
e.style.display = 'none';
}

function toggle_visibility(id) {
var e = document.getElementById(id);
if(e.style.display == 'none')
e.style.display = '';
else
e.style.display = 'none';
}

function Disable_Pro_Special_Carriage(status)
{
if (document.getElementById('procarriagerate').disabled)
document.getElementById('procarriagerate').disabled  = false;
else
document.getElementById('procarriagerate').disabled  = true;
}

function Disable_TGI_Special_Carriage(status)
{
if (document.getElementById('tgicarriagerate').disabled)
document.getElementById('tgicarriagerate').disabled  = false;
else
document.getElementById('tgicarriagerate').disabled  = true;
}


function enable_text(status)
{
status=!status; 
document.getElementById('normalproprice').disabled = status;
document.getElementById('specialpro').disabled = status;
document.getElementById('procrriageinc').disabled = status;
}

function enable_TGI_text(status)
{
status=!status; 
document.getElementById('normaltgiprice').disabled = status;
document.getElementById('specialtgi').disabled = status;
document.getElementById('tgicrriageinc').disabled = status;
}


function enable_TGI_Special_Offer(status)
{
status=!status; 
document.getElementById('displayspecialpricetgi').disabled = status;
document.getElementById('displayspecialdesctgi').disabled = status;

}

function enable_PRO_Special_Offer(status)
{
status=!status; 
document.getElementById('displayspecialpricepro').disabled = status;
document.getElementById('displayspecialdescpro').disabled = status;

}

function enable_TGI_Special_Price(status)
{
status=!status; 
document.getElementById('saletgiprice').disabled = status;
}

function enable_PRO_Special_Price(status)
{
status=!status; 
document.getElementById('saleproprice').disabled = status;
}

Open in new window


These work fine for my new product form, but I'm building an edit product form and currently I have checkboxes like =

<input <%If (CStr((RsEditProduct.Fields.Item("DisplayTGI").Value)) = CStr("Y")) Then Response.Write("checked=""checked""") : Response.Write("")%> name="displaytgi" type="checkbox" id="displaytgi" value="Y" onClick="enable_TGI_text(this.checked);toggle_visibility('TGI-Direct-Pricing-Wrapper');toggle_visibility('TGI-Direct-Carriage-Wrapper')"/>

Open in new window


What I want to achive is areas are already hidden if checkbox is not selected when the page loads...

I hope this makes sense..

thank you
0
Comment
Question by:garethtnash
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 2000 total points
ID: 36554427
>What I want to achive is areas are already hidden if checkbox is not selected when the page loads...

use CSS in head section :
<style type="text/css">
#LSpecialDescriptionTGI, #ULSpecialDescriptionPro, #Pro-Direct-Special-Header, #TGI-Direct-Special-Header, #TGI-Direct-Pricing-Wrapper, #TGI-Direct-Carriage-Wrapper, #PRO-Direct-Pricing-Wrapper, #PRO-Direct-Carriage-Wrapper {
   display:none;
}
</style>

Open in new window


or set the same class for every wrapper for example : wrappers
<style type="text/css">
.wrappers {
   display:none;
}
</style>

Open in new window

0
 

Author Comment

by:garethtnash
ID: 36911954
Hi LeaKim,

Firstly apologies for the delayed response, I was on leave and far from a PC.

Thank you your solution works a treat, however I have a checkbox at the top of the form that should allow me o toggle visibility....

So what I have done (for test purposes is)

added this in the head section -

<%If (CStr((RsEditProduct.Fields.Item("DisplayTGI").Value)) = CStr("Y")) Then%>
<style type="text/css">
#TGI-Direct-Pricing-Wrapper,
#TGI-Direct-Carriage-Wrapper {
   display:none;
}
</style>
<%End IF%>

added this to the checkbox -

<input <%If (CStr((RsEditProduct.Fields.Item("DisplayTGI").Value)) = CStr("Y")) Then Response.Write("checked=""checked""") : Response.Write("")%> name="displaytgi" type="checkbox" id="displaytgi" value="Y" onClick="enable_TGI_text(this.checked);toggle_visibility('TGI-Direct-Pricing-Wrapper');toggle_visibility('TGI-Direct-Carriage-Wrapper')"/>

And added the following script -

<script>
function toggle_visibility(id) {
var e = document.getElementById(id);
if(e.style.display == 'none')
e.style.display = '';
else
e.style.display = 'none';
}
</script>

I'm actually (in the test) doing the opposite I'm hiding the areas if checkbox = Y and trying to toggle visibility on checkbox change..

Is this possible?

Once again -

Many thanks

0
 

Author Closing Comment

by:garethtnash
ID: 36912172
Sorry for the delay :)
0
 
LVL 82

Expert Comment

by:leakim971
ID: 36912545
no worry, look like you find your second issue, see you later
thanks for the points
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question