Forum FAQForum FAQSearchSearch MemberlistMemberlist Forum ignore listForum ignore list RegisterRegister ProfileProfile Log in to check your private messagesLog in to check your private messages Log inLog in
js/css <div> visibility question

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    mi3dot.org Forum Index -> Client-side
View previous topic :: View next topic  
Author Message
budha



Joined: 02 Mar 2004
Posts: 1377
Location: Osijek

PostPosted: 16.11.2004 16:40    Post subject: js/css <div> visibility question Add user to your forum ignore list Reply with quote

sad bi se najradije otrovao Embarassed Smile

imam 3 <input type="checkbox"> i 3 <div>-a, i kako sada rjesiti da mi style.visibility svakog od div-ova odgovara stanju njemu pripadajuceg checkbox-a?

znaci..
- kad mi je checkbox1 "ukljucen", da je div1 visible
- a kad je checkbox1 "iskljucen", da je div1 hidden

help pliiiiz!

_________________
I hate to advocate drugs, alcohol, violence, or insanity to anyone, but they've always worked for me.
Back to top
View user's profile Send private message Visit poster's website
zytzagoo
mi3.crew


Joined: 25 Aug 2003
Posts: 1842
Location: Zagreb, Hrvatska

PostPosted: 16.11.2004 19:20    Post subject: Add user to your forum ignore list Reply with quote

Pisem iz glave, moglo bi nesto i ne sljakati...

Code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?xml version="1.0" encoding="iso-8859-2"?>
<html xmlns="http://www.w3.org/1999/xhtml" lang="hr-HR" xml:lang="hr-HR">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>div visibility playground</title>
    <script type="text/javascript">
    function checkbox_trigger(cbObj, divID) {
        if (document.getElementById) {
            document.getElementById(divID).style.display = cbObj.checked ? 'block' : 'none';
        } else if (document.all) {
            document.all.divID.style.display = cbObj.checked ? 'block' : 'none';
        } else {
            // neda mi se dalje, inako pisem iz glave,
            // ali ovo gore pokriva firefox, operu, mozillu, te IE u najmanju ruku
        }
    }
    </script>
</head>
<body>

<input type="checkbox" id="checkbox1" name="checkbox1" value="neki" onclick="checkbox_trigger(this, 'div1');" />
<input type="checkbox" id="checkbox2" name="checkbox2" value="neki" onclick="checkbox_trigger(this, 'div2');" />
<input type="checkbox" id="checkbox3" name="checkbox3" value="neki" onclick="checkbox_trigger(this, 'div3');" />

<div id="div1" style="display: none;">div1</div>
<div id="div2" style="display: none;">div2</div>
<div id="div3" style="display: none;">div3</div>

</body>
</html>

_________________
[+]I[+]am[+]my[+]own[+]religion[+]
Back to top
View user's profile Send private message Visit poster's website Twitter profile
zytzagoo
mi3.crew


Joined: 25 Aug 2003
Posts: 1842
Location: Zagreb, Hrvatska

PostPosted: 16.11.2004 19:23    Post subject: Add user to your forum ignore list Reply with quote

Upravo snimih ovo kao .html (copy-paste) - radi od prve LeaveMeBe

EDIT: naravno, ima dosta mjesta za poboljsati kod:
- logiku koji div se switcha je bolje napraviti ovisno o tome koji je checkbox stisnut, a ne da se id prenosi funkciji kao string
- mogla bi f-cja mozda pamtiti state bez da querya svaki put cbObj za njegovo stanje
- moglo bi se jos dodati return value funkcije mozda iako ne mogu smisliti zasto trenutno Smile
- ne koristiti onclick event nego nesto bolje jer useri bez misa ne trigeraju onclick (jel radi onchange na checkboxu?)
- eventualno postojanje konfiguracijske varijable pa ovisno o njoj raditi toggle preostalih divova i sl..
- moglo bi se toga jos dosta smisliti Smile

_________________
[+]I[+]am[+]my[+]own[+]religion[+]
Back to top
View user's profile Send private message Visit poster's website Twitter profile
aesqe



Joined: 18 Sep 2003
Posts: 48
Location: zagreb

PostPosted: 16.11.2004 19:51    Post subject: Add user to your forum ignore list Reply with quote

dobar Smile

onchange radi, ofkors.

super mi je kad ljudi tako razmisljaju, stvarno hvalevrijedno Wink

_________________
-_-_-_-__oops, missed one-_-_--again_-
::skyphe:: : ::breed::
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
budha



Joined: 02 Mar 2004
Posts: 1377
Location: Osijek

PostPosted: 16.11.2004 20:28    Post subject: Add user to your forum ignore list Reply with quote

yupiiiiiii!1

ma ja sam nest kemijo, al se (idiot) nisam sjetio staviti i drugu varijablu u f-iju rrrrrrrah pa mi je stalno falilo nest da znam koje je trenutno stanje Brick wall

fala! Pray

_________________
I hate to advocate drugs, alcohol, violence, or insanity to anyone, but they've always worked for me.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    mi3dot.org Forum Index -> Client-side All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group