Solved

my javascript on load if select box checked

Posted on 2011-09-17
4
222 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
  • 2
  • 2
4 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…

863 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now