Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Oct 2013
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Multiple toggle buttons popup opener

    Hello boys and girls,


    I want to create multiple toggle buttons to open and close specific window popups using 1 code.

    Button1 opens window1, when pressed again it closes window1, button2 opens window2, when pressed again it closes window2, etc.
    What i need is to set a variable window name depending on wich button is pressed so the button that opens the window also closes that specific window only.

    the code below is as far as i am but doesn't work as explained above.


    Code:
    <input type="button" value="OFF" id="Window1" onclick="toggle('Window1')">
    <input type="button" value="OFF" id="Window2" onclick="toggle('Window2')">
    
    function toggle(id){
    if(document.getElementById(id).value=="ON"){
    	document.getElementById(id).value="OFF";
    	popout.close();
    	}
    else if(document.getElementById(id).value=="OFF"){
    	document.getElementById(id).value="ON";
    	popout = window.open("URL",id,"settings");
    	}
    }


    My question is:
    Can "popout" be set as a variable set by the pressed button and how can i recall it?

    With kind regards,

    Gila

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,949
    Thanks
    0
    Thanked 236 Times in 233 Posts
    Code:
    <input type="button" value="OFF" id="Window1" onclick="toggle(this);" />
    <input type="button" value="OFF" id="Window2" onclick="toggle(this);" />
    PHP Code:
    function toggle(btn){
        if (
    btn.value == "ON"){
            
    btn.value "OFF";
            if (
    btn.popout && !btn.popout.closed) {
                
    btn.popout.close();
            }
        }
        else {
            
    btn.value "ON";
            
    btn.popout window.open("URL"btn.id"settings");
        }


  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,949
    Thanks
    0
    Thanked 236 Times in 233 Posts
    I don't know where you would get the URL for each popup but you can put it in the button markup like this:

    Code:
    <input type="button" value="OFF" id="Window1" onclick="toggle(this);" data-url="page1.htm" />
    <input type="button" value="OFF" id="Window2" onclick="toggle(this);" data-url="page2.htm" />
    PHP Code:
    function toggle(btn){
        if (
    btn.value == "ON"){
            
    btn.value "OFF";
            if (
    btn.popout && !btn.popout.closed) {
                
    btn.popout.close();
            }
        }
        else {
            
    btn.value "ON";
            
    btn.popout window.open(btn.getAttribute('data-url'), btn.id"settings");
        }


  • #4
    New to the CF scene
    Join Date
    Oct 2013
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks for the reply!

    Unfortunatly I'm not familiar with php and would like to do this in javascript and html as I know a little more of that.

    Quote Originally Posted by glenngv View Post
    I don't know where you would get the URL for each popup but you can put it in the button markup like this:
    I've put a more complete code below, so you can see or try out how it works and where I get the url from. The script is not completed yet cause i've just started. I still have to make inputs for size and screen location. But I will do that after I fixed this issue.

    The problem with this code is:
    If you click button1 to open window1,
    then click button2 to open window2,
    and then click button1 again to close window1, it closes window2.
    This is because both windows are called "popout"

    So my question remains, can "popout" be set as a variable set by the pressed button (something like the id) and how can i recall it?

    Code:
    <body>
    <input type="text" name="channelname" placeholder="channel..." value="" id="CHAN" style="background-color:000000; color:ffffff; border-color:222222; font:verdana; font-size:10; height:20; width:199;">
    	
    <input type="button" value="X" id="Window1" onclick="toggle('Window1','400','200');" style="color:#006600;background:#006600;border-color:#006600;width:20;"/>
    <input type="button" value="X" id="Window2" onclick="toggle('Window2','800','400');" style="color:#006600;background:#006600;border-color:#006600;width:20;"/>
    
    <script language=javascript>
    
    function toggle(id,pw,ph){
    
    	if(document.getElementById(id).value=="|"){
    	document.getElementById(id).value="X";
    	document.getElementById(id).style.color="006600";
    	document.getElementById(id).style.background="#006600";
    	document.getElementById(id).style.borderColor="#006600";
    	popout.close();
    	}
    
    	else if(document.getElementById(id).value=="X"){
    	document.getElementById(id).value="|";
    	document.getElementById(id).style.color="00AA00";
    	document.getElementById(id).style.background="#00AA00";
    	document.getElementById(id).style.borderColor="#00AA00";
    	popout = window.open(CHAN.value,id,"directories=0,toolbar=0,location=0,width=" + pw + ",height=" + ph + ",top=0,left=0,resizable=1");
    	}
    }
    
    </script>
    </body>

    Again thanks for the reply,

    GILA

  • #5
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,471
    Thanks
    6
    Thanked 980 Times in 953 Posts
    Quote Originally Posted by Gila View Post
    Unfortunatly I'm not familiar with php and would like to do this in javascript and html as I know a little more of that.
    There is no PHP at all in this thread. It only says “PHP code” above the code block but it’s still JavaScript since the syntax is similar enough to make use of the syntax highlighting.

  • #6
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,949
    Thanks
    0
    Thanked 236 Times in 233 Posts
    Yeah that's not PHP. Just try my suggestion and see if it works for you.

  • Users who have thanked glenngv for this post:

    Gila (10-17-2013)

  • #7
    New to the CF scene
    Join Date
    Oct 2013
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Hey guys,

    Sorry for the late reply, been kinda busy.

    Tnx for the help


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •