Javascript Popup Windows

Posted by sikas on Stack Overflow See other posts from Stack Overflow or by sikas
Published on 2011-01-13T13:33:50Z Indexed on 2011/01/13 13:53 UTC
Read the original article Hit count: 202

Filed under:
|
|
|

I have a popup window code that I have used before in login forms. The code displays an in-page popup.

This is the code:

<?php
//In Page Popup Box with Faded Background by Jerry Low @crankberryblog.com
//Find other useful scripts at the Crankberry Blog

//SETTINGS
$fade_amount = 60;                              //In Percentage
$box_width = 400;
$box_background = 'FFFFFF';             //Hex Color
$box_border_width = 2;
$box_border_color = '999999';   //Hex Color
$close_box = 1;                 //Do You Want The Close Bar on Top 1 = Yes, 0 = No
$extension = "";                // Other Variables that maybe needed, page number etc.

//Begin Popup Box
$left_margin = ( 0 - ($box_width*0.5) );
$page_url = basename($_SERVER['PHP_SELF']);
if ($extension!="") $page_url .= '?' . $extension;

if (isset($_GET['popup'])) {
        echo '<div class="popup" style="width:'.$box_width.'px; background: #'.$box_background.';  margin-left:'.$left_margin.'px;';
        if ($box_border_width>1) echo ' border: '.$box_border_width.'px solid #'.$box_border_color.';';
        echo '">';

        //Close Box
        if ($close_box===1) echo '<div class="popup_close"><a href="'.$page_url.'">Close (x)</a></div>';

        ?>
        <!–- START YOUR POPUP CONTENT HERE -–>

    Popup content goes in here!

        <!–- END OF YOUR POPUP CONTENT HERE -–>
        <?php

        echo '</div>
    <div class="fade" onclick="location.replace(\''.$page_url.'\');" style="opacity: 0.'.$fade_amount.';  -moz-opacity: 0.'.$fade_amount.';filter: alpha(opacity: '.$fade_amount.');"></div>
    <div class="fade_container">';

}

?>

<a href="?popup=1<?php if ($extension!="") echo '&' . $extension; ?>">Activated Box</a>

This code contains a link that reloads the page with parameters/arguments to show the popup.

I want to update this code to make the popup appear/hide without

This is what I have done so far, yet the popup doesn`t show.

Now I want to update the code to work as follows.

<link rel=StyleSheet href="css/popup.css" type="text/css" media=screen></link>
<?php
//In Page Popup Box with Faded Background by Jerry Low @crankberryblog.com
//Find other useful scripts at the Crankberry Blog

//SETTINGS
$fade_amount = 60;                              //In Percentage
$box_width = 400;
$box_background = 'FFFFFF';             //Hex Color
$box_border_width = 2;
$box_border_color = '999999';   //Hex Color
$close_box = 1;                 //Do You Want The Close Bar on Top 1 = Yes, 0 = No
$extension = "";                // Other Variables that maybe needed, page number etc.

//Begin Popup Box
$left_margin = ( 0 - ($box_width*0.5) );
$page_url = basename($_SERVER['PHP_SELF']);
if ($extension!="") $page_url .= '?' . $extension;

{
        echo '<div id="pop_up" class="popup" style="visibility:hidden; width:'.$box_width.'px; background: #'.$box_background.';  margin-left:'.$left_margin.'px;';
        if ($box_border_width>1) echo ' border: '.$box_border_width.'px solid #'.$box_border_color.';';
        echo '">';

        //Close Box
        if ($close_box===1) echo '<div class="popup_close"><a href="#" ChangeStatus()>Close (x)</a></div>';

        ?>
        <!–- START YOUR POPUP CONTENT HERE -–>

    Popup content goes in here!

        <!–- END OF YOUR POPUP CONTENT HERE -–>
        <?php

        echo '</div>
    <div id="fade_div" class="fade" onclick="location.replace(\''.$page_url.'\');" style="visibility:hidden; opacity: 0.'.$fade_amount.';  -moz-opacity: 0.'.$fade_amount.';filter: alpha(opacity: '.$fade_amount.');"></div>
    <div class="fade_container">';

}

?>

<a href="#" onClick="ChangeStatus()">Activated Box</a>

<script>
function ChangeStatus()
{
    div = document.getElementById('fade_div').style.visibility;
    popup = document.getElementById('pop_up').style.visibility;
    alert(popup);
    if(popup == "hidden")
    {
        div = "visible";
        popup = "visible";
    }
    else
    {
        div = "hidden";
        popup = "hidden";
    }
}
</script>

ignore the CSS files as it is working fine.

I guess the problem is with the JS. Can anyone help me?

© Stack Overflow or respective owner

Related posts about php

Related posts about JavaScript