Solved

my javascript on load if select box checked

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

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

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

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

734 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