Visualizzazione dei risultati da 1 a 4 su 4

Discussione: checkbox e div

  1. #1

    checkbox e div

    ragazzi salve a tutti
    allora io ho il seguente problema
    vorrei che la mia checkbox nel momento in cui ci clicco per mettere una spunta mi tirasse fuori il contenuto di una tabella inserita in una DIV.

    vorrei però che nel momento in cui la pagina venga aperta la DIV compaia soltanto quando il checkbox è spuntato.... sia in apertura e sia nel refresh della pagina ..è possibile?????

    cioè non so se il controllo va messo nel body onload...
    cioè la pagina deve controllare che il checkbox sia su "si" o su "no"
    se è su "SI" deve resitutirmi il DIV se è su NO non deve restituirmi nulla....
    mi aiutate???
    Grazie mille

  2. #2
    Utente di HTML.it
    Registrato dal
    Apr 2000
    Messaggi
    938
    Ciao,

    <script type="text/javascript">
    <!--
    function attiva(){
    var f = document.mioform;
    if(!f.abilita.checked){
    document.getElementById("object").style.visibility ='hidden';
    }else{
    document.getElementById("object").style.visibility ='visible';
    }
    }
    // -->
    </script>
    </head>
    <body>
    <form name="mioform">
    <input type="checkbox" name="abilita" onclick="attiva()">
    </form>

    <div id="object" name="object" style="visibility:hidden"><table border="1"><tr><td>TESTO</td></tr></table></div>


    Massimo

  3. #3
    grazie mille va bene
    però c'è un problema ...cioè dopo il div che è impostato su HIDDEN ho due bottoni CONFERMA e CHIUDI ed in questo modo sono troppo giù....
    come potrei risolvere???

  4. #4
    io avevo fatto cosi

    nell' head avevo messo questo script

    <script type="text/javascript">

    var enablepersist="on"

    if (document.getElementById){
    document.write('<style type="text/css">')
    document.write('.switchcontent{display:none;}')
    document.write('</style>')
    }

    function getElementbyClass(classname){
    ccollect=new Array()
    var inc=0
    var alltags=document.all? document.all : document.getElementsByTagName("*")
    for (i=0; i<alltags.length; i++){
    if (alltags[i].className==classname)
    ccollect[inc++]=alltags[i]
    }
    }

    function contractcontent(omit){
    var inc=0
    while (ccollect[inc]){
    if (ccollect[inc].id!=omit)
    ccollect[inc].style.display="none"
    inc++
    }
    }

    function expandcontent(cid){
    if (typeof ccollect!="undefined"){
    contractcontent(cid)
    document.getElementById(cid).style.display=(docume nt.getElementById(cid).style.display!="block")? "block" : "none"
    selectedItem=cid+"|"+document.getElementById(cid). style.display
    }
    }

    function revivecontent(){
    selectedItem=getselectedItem()
    selectedComponents=selectedItem.split("|")
    contractcontent(selectedComponents[0])
    document.getElementById(selectedComponents[0]).style.display=selectedComponents[1]
    }

    function get_cookie(Name) {
    var search = Name + "="
    var returnvalue = "";
    if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
    if (offset != -1) {
    offset += search.length
    end = document.cookie.indexOf(";", offset);
    if (end == -1) end = document.cookie.length;
    returnvalue=unescape(document.cookie.substring(off set, end))
    }
    }
    return returnvalue;
    }

    function getselectedItem(){
    if (get_cookie(window.location.pathname) != ""){
    selectedItem=get_cookie(window.location.pathname)
    return selectedItem
    }
    else
    return ""
    }

    function saveswitchstate(){
    if (typeof selectedItem!="undefined")
    document.cookie=window.location.pathname+"="+selec tedItem
    }

    function do_onload(){
    getElementbyClass("switchcontent")
    if (enablepersist=="on" && getselectedItem()!="")
    revivecontent()
    }


    if (window.addEventListener)
    window.addEventListener("load", 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=saveswitchstate

    </script>

    </head>

    <body>

    <input id="A21" type=checkbox onClick="if(this.checked){ expandcontent('sc1') } else { document.getElementById('sc1').style.display='none ' }" Name="A21" value="1" style="background-color: #FFFFD9">

    <div align=center id="sc1" class="switchcontent">prova</div>

    va bene ma quando faccio il refresh della pagina il DIV è presente anche se il checkbox non è checked.... io vorrei che nel refresh fosse presente quando la checkbox è checked e non presente quando la checkbox non è checked

    Mi aiutate per favore???? grazie

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.