Welcome to WebmasterWorld Guest from 54.145.13.215

Forum Moderators: open

Message Too Old, No Replies

getElementById Help

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

Junior Member

5+ Year Member

joined:Sept 10, 2008
posts: 79
votes: 0


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)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Nov 3, 2005
posts:1585
votes: 0


<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>