Solved

my javascript on load if select box checked

Posted on 2011-09-17
4
225 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Find out what you should include to make the best professional email signature for your organization.
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…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

726 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