Reputation: 81
I am trying to display a div based on the URL parameter. I have to use only html css and javascript. I got it working until the part where the div must be set to display none if the variable (parameter from URL) matches.
HTML
<div id="cfiblinks">
<div class="row">
<div class="twelve columns">
<ul class="nav-bar">
<li>
<a href="#" target="_blank">
<span>Order Document Upload</span>
</a>
</li>
<li>
<a href="#" target="_blank">
<span>Business Card History</span>
</a>
</li>
<li>
<a href="#" target="_blank">
<span>Material Inventory</span>
</a>
</li>
</ul>
</div>
</div>
</div>
Javascript
<script language="JavaScript">
function getURLParameter(name) {
return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[""])[1].replace(/\+/g, '%20'))||null
}
myvar = getURLParameter('UserGroupId');
document.write('The url parameter is: ' + myvar +' ');
if (myvar == 10102) {
document.write('The url parameter is: ' + myvar +' ');
document.getElementById('cfiblinks').style.visibility = 'visible';
} else {
document.write('The url parameter is not : ' + myvar +' ');
document.getElementById('cfiblinks').style.visibility = 'hidden';
}
</script>
Any help would be greatly appreciated. I suspect something is wrong with the document.getElementById.
Upvotes: 1
Views: 16403
Reputation: 1838
Try this..
if (myvar == 10102) {
document.write('The url parameter is: ' + myvar +' ');
document.getElementById('cfiblinks').setAttribute("style", "display:block");
} else {
document.write('The url parameter is not : ' + myvar +' ');
document.getElementById('cfiblinks').setAttribute("style", "display:none");
}
Upvotes: 1
Reputation: 198
Try:
document.getElementById('something').style.display = "block";
and
document.getElementById('something').style.display = "none";
Upvotes: 0
Reputation: 3892
You can set the display property using block or none.
document.getElementById('cfiblinks').style.display = 'block'; //Will show
document.getElementById('cfiblinks').style.display = 'none'; //Will hide
Upvotes: 2