Hello,
I have a Checkbox that, when unchecked, expands Credit Card information. What I have currently works on initial upload to my IE browser. That is, the box default is checked, and Credit Card information does not appear. However, when I refresh the browser, the Checkbox remains checked and the Credit Card information expands itself.
My toggle seems to work when I uncheck the Checkbox, then re-check it. The whole problem is that something in my code is "buggy" if somebody refreshes my site or re-enters later.
Here is my javascript:
--------------------------
----------
----------
--------
var enablepersist="on" //Enable saving state of content structure? (on/off)
if (document.getElementById){
document.write('<style type="text/css">')
document.write('.switchcon
tent{displ
ay:none;}'
)
document.write('</style>')
}
function getElementbyClass(classnam
e){
ccollect=new Array()
var inc=0
var alltags=document.all? document.all : document.getElementsByTagN
ame("*")
for (i=0; i<alltags.length; i++){
if (alltags[i].className==cla
ssname)
ccollect[inc++]=alltags[i]
}
}
function contractcontent(omit){
var inc=0
while (ccollect[inc]){
if (ccollect[inc].id!=omit)
ccollect[inc].style.displa
y="none"
inc++
}
}
function expandcontent(cid){
if (typeof ccollect!="undefined"){
document.getElementById(ci
d).style.d
isplay=(do
cument.get
ElementByI
d(cid).sty
le.display
!="block")
? "block" : "none"
selectedItem=cid+"|"+docum
ent.getEle
mentById(c
id).style.
display
}
}
function closecontent(tid){
if (typeof ccollect!="undefined"){
document.getElementById(ti
d).style.d
isplay= "none"
selectedItem=tid+"|"+docum
ent.getEle
mentById(t
id).style.
display
}
}
function opencontent(sid){
if (typeof ccollect!="undefined"){
document.getElementById(si
d).style.d
isplay= "block"
selectedItem=sid+"|"+docum
ent.getEle
mentById(s
id).style.
display
}
}
function revivecontent(){
selectedItem=getselectedIt
em()
selectedComponents=selecte
dItem.spli
t("|")
contractcontent(selectedCo
mponents[0
])
document.getElementById(se
lectedComp
onents[0])
.style.dis
play=selec
tedCompone
nts[1]
}
function get_cookie(Name) {
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(se
arch)
if (offset != -1) {
offset += search.length
end = document.cookie.indexOf(";
", offset);
if (end == -1) end = document.cookie.length;
returnvalue=unescape(docum
ent.cookie
.substring
(offset, end))
}
}
return returnvalue;
}
function getselectedItem(){
if (get_cookie(window.locatio
n.pathname
) != ""){
selectedItem=get_cookie(wi
ndow.locat
ion.pathna
me)
return selectedItem
}
else
return ""
}
function saveswitchstate(){
if (typeof selectedItem!="undefined")
document.cookie=window.loc
ation.path
name+"="+s
electedIte
m
}
function do_onload(){
getElementbyClass("switchc
ontent")
if (enablepersist=="on" && getselectedItem()!="")
revivecontent()
for(i=0;i<ccollect.length;
i++){
if(ccollect[i].id.replace(
/\d/g,'')=
="C"){
expandcontent(ccollect[i].
id)
}
}
}
function toggle(theLink){
theDiv = theLink.parentNode;
while(theDiv.nodeName!="DI
V"){
theDiv = theDiv.parentNode;
}
iNum = theDiv.id.replace(/\D/g,''
);
dTyp = theDiv.id.replace(/\d/g,''
);
dNext = (dTyp=="C")?"O":"C";
document.getElementById(dN
ext+iNum).
style.disp
lay = "block";
theDiv.style.display = "none";
}
function expand(theBox){
var cEx = (theBox.checked==true)?"O"
:"C";
for(i=0;i<ccollect.length;
i++){
closecontent(ccollect[i].i
d)
if(ccollect[i].id.replace(
/\d/g,'')=
=cEx){
expandcontent(ccollect[i].
id)
}
}
}
function contract(theBox){
var cEx = (theBox.checked==false)?"O
":"C";
for(i=0;i<ccollect.length;
i++){
closecontent(ccollect[i].i
d)
if(ccollect[i].id.replace(
/\d/g,'')=
=cEx){
expandcontent(ccollect[i].
id)
}
}
}
if (window.addEventListener)
window.addEventListener("l
oad", do_onload, false)
else if (window.attachEvent)
window.attachEvent("onload
", do_onload)
else if (document.getElementById)
window.onload=do_onload
if (enablepersist=="on" && document.getElementById)
window.onunload=saveswitch
state
--------------------------
----------
----------
----------
---
Here's my function call:
<td width="875"><font size="3">Method of payment:</font> <form><font face="Verdana" size="2">
<input type="checkbox" onclick="expand(this)" name="Subscribe2" value="Subscribe2" checked="checked" style="font-style: normal; font-variant: normal; font-weight: bold; font-size: 11px; font-family: Verdana, arial, sans-serif; height: 18; width:20">Please
use my existing method of payment on file</font></form></td>
<div id="c2" class="switchcontent">
</table>
</div>
<td align="left">
</td>
</tr>
</table>
<table class="table-body" bgcolor="#ffffee" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="95">
<form><font face="Verdana" size="2">
</form></td>
<td>
<div id="C1" class="switchcontent">
<table width="549" cellpadding="0" cellspacing="0" style="border: 0px dashed green;">
<tr>
<td style="padding-right: 50px; padding-bottom: 20px;">
<p align="left"> <p align="left"><font size="2">
<select name="Card" style="font-style: normal; font-variant: normal; font-weight: bold; font-family: Verdana, arial, sans-serif; height: 19; width: 182">
<option>--- Please select one ---</option>
<option selected value="Mastercard">Masterc
ard</optio
n>
<option value="Visa">Visa</option>
<option value="Discover">Discover<
/option>
<option value="AMEX">AMEX</option>
</SELECT></font> &nbs
p;
<font size="2"> Card #:
<INPUT type="text" name="Name2" size="2" maxlength="35" style="font-style: normal; font-variant: normal; font-weight: bold; font-family: Verdana, arial, sans-serif; height: 21; width: 138; font-size:11px"></font>
</td>
</tr>
</table>
</div>
</td>
--------------------------
----------
----------
----------
------
Assistance is definitely appreciated! Thank you in advance.
Chad
Start Free Trial