I wrote a script to expand and collapse a paragraph on my page, with cookies, and it works great. However I can't figure out how to change the button value. Basically the page loads with all the paragraphs collapsed, and a plus button under the heading. I want to change the plus button to a minus button when the paragraphs are expanded. I tried doing this with an if statement toggle function, and it worked, however it broke the rest of the script and the cookies. Any ideas?
Code:function checkPage() { toggle('menu1', getCookie('menu1')); toggle('menu2', getCookie('menu2')); } var inputs = new Array(); function setPage() { var menus = document.getElementsByTagName("ul"); var menusElems = new Array(); for(var i = 0; i <menus.length; i++) { if(menus[i].className=="menuList") { menusElems.push(menus[i]); } } for(var j = 0; j< menusElems.length; j++) { menusElems[j].style.display = "block"; } inputs = document.getElementsByClassName("inputA"); for(var i =0; i<inputs.length; i++) { inputs[i].value = "+"; } checkPage(); } var displayValue; function toggle(id, displayValue) { var obj = document.getElementById(id); if(!displayValue) { var displayValue = (obj.style.display!='none')?'none':'block'; } obj.style.display = displayValue; setCookie(id, displayValue, 30); return; } function setCookie(name, value, expires) { var date = new Date(); date.setTime(date.getTime()+(expires*24*60*60*1000)); expires ="; expires="+ date.toGMTString(); document.cookie = name + "=" + value + expires + "; path=/"; } function getCookie(searchName) { if (document.cookie.length>0) { var nameValuePair, cookieName, cookieValue var pairs = document.cookie.split(';'); for(var i=0; i<pairs.length; i++) { nameValuePair = pairs[i].split('='); cookieName = nameValuePair[0].replace(/^\s+|\s+$/g,''); cookieValue = nameValuePair[1].replace(/^\s+|\s+$/g,''); if(cookieName == searchName) { return cookieValue; } } } return false; }



Reply With Quote
Bookmarks