Solved

show layer based on querystring value onload

Posted on 2009-07-07
2
344 Views
Last Modified: 2012-05-07
What I am trying to do is SHOW a hidden div when the querystring variable Login = "Failed". So far I have got the variable value bit working and it is alerting that the value is "Failed" but actually showing the div is resulting in an error which is "Object required".

Do I need to add an event to the body dynamically in relation to the variable value and if so how do I do this?
HTML Page
--------------
<script language="javascript">
var qs = new Querystring()
var v1 = qs.get("Login");
alert(v1); //WORKS UP TO HERE
if(v1 == "Failed") {
	slidedown('mydiv');
}
 
 
JS FILE
--------------
var timerlen = 5;
var slideAniLen = 250;
 
var timerID = new Array();
var startTime = new Array();
var obj = new Array();
var endHeight = new Array();
var moving = new Array();
var dir = new Array();
 
function slidedown(objname){
        if(moving[objname])
                return;
 
        if(document.getElementById(objname).style.display != "none")
                return; // cannot slide down something that is already visible
 
        moving[objname] = true;
        dir[objname] = "down";
        startslide(objname);
}
 
function slideup(objname){
        if(moving[objname])
                return;
 
        if(document.getElementById(objname).style.display == "none")
                return; // cannot slide up something that is already hidden
 
        moving[objname] = true;
        dir[objname] = "up";
        startslide(objname);
}
 
function startslide(objname){
        obj[objname] = document.getElementById(objname);
 
        endHeight[objname] = parseInt(obj[objname].style.height);
        startTime[objname] = (new Date()).getTime();
 
        if(dir[objname] == "down"){
                obj[objname].style.height = "1px";
        }
 
        obj[objname].style.display = "block";
 
        timerID[objname] = setInterval('slidetick(\'' + objname + '\');',timerlen);
}
 
function slidetick(objname){
        var elapsed = (new Date()).getTime() - startTime[objname];
 
        if (elapsed > slideAniLen)
                endSlide(objname)
        else {
                var d =Math.round(elapsed / slideAniLen * endHeight[objname]);
                if(dir[objname] == "up")
                        d = endHeight[objname] - d;
 
                obj[objname].style.height = d + "px";
        }
 
        return;
}
 
function endSlide(objname){
        clearInterval(timerID[objname]);
 
        if(dir[objname] == "up")
                obj[objname].style.display = "none";
 
        obj[objname].style.height = endHeight[objname] + "px";
 
        delete(moving[objname]);
        delete(timerID[objname]);
        delete(startTime[objname]);
        delete(endHeight[objname]);
        delete(obj[objname]);
        delete(dir[objname]);
 
        return;
}
 
function toggleSlide(objname){
  if(document.getElementById(objname).style.display == "none"){
    // div is hidden, so let's slide down
    slidedown(objname);
  }else{
    // div is not hidden, so slide up
    slideup(objname);
  }
}
</script>
 
<body>
    <div id="mydiv" style="display:none; overflow:hidden; height:35px; width:920px; margin:0px auto; padding:0px 20px; background-color:#000; color:#fff;"> </div>

Open in new window

0
Comment
Question by:clearchannel
2 Comments
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 500 total points
ID: 24793201
Here

You need the div to exist so you have to wait until after load

<script language="text/javascript">
var qs = new Querystring()
var v1 = qs.get("Login");
alert(v1); //WORKS UP TO HERE
window.onload=function() {
  if(v1 == "Failed") {
    slidedown('mydiv');
  }
}
</script>
 

Open in new window

0
 

Author Comment

by:clearchannel
ID: 24793639
Thanks. I thought it had somehitng to do with onload but wasn't sure.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Jquery 2 23
Using toggleClass to resize Bootstrap columns 7 22
Only allow one check box 17 27
I'm a Human captcha checkbox 13 23
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question