Welcome to WebmasterWorld Guest from 54.145.209.34

Forum Moderators: open

getElementById Help

   
8:33 pm on Nov 12, 2009 (gmt 0)

5+ Year Member



Hi everyone,

Im looking for some help.

I have a site that has people in several areas of the country. Im building a dropdown that will show that specific location. The script looks like this

<script type="text/javascript"><!--
var lastDiv = "";
function showDiv(divName) {
// hide last div
if (lastDiv) {
document.getElementById(lastDiv).className = "hiddenDiv";
}
//if value of the box is not nothing and an object with that name exists, then change the class
if (divName && document.getElementById(divName)) {
document.getElementById(divName).className = "visibleDiv";
lastDiv = divName;
}
}
//-->
</script>

Now there are not any peole in some areas so Id like to create a code that will do that to. For example:

"No one is in that area. Be the first"

Is there something I can do to create this script without just duplicating "No one is in that area. Be the first" so many times on the page?

Does this make sense? Thanks in advance

7:11 am on Nov 13, 2009 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



<script type="text/javascript"><!--
var lastDiv = "";
function showDiv(divName) {
if ( divName !== "" ) {
// hide last div
if (lastDiv) {
document.getElementById(lastDiv).className = "hiddenDiv";
}
//if value of the box is not nothing and an object with that name exists, then change the class
if (document.getElementById(divName)===null) {divName="welcomeId"; }
document.getElementById(divName).className = "visibleDiv";
lastDiv = divName;
}
}

//-->
</script>

HTML
<div id="welcomeId" class="hiddenDiv" >....</div>

 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month