Forum Moderators: open

Message Too Old, No Replies

Show content with two parameters

         

toplisek

9:56 am on Jan 23, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I have tested script to show content but two parameters (two listboxes).
Is this script correct as it does not work.
<script type="text/javascript" language="JavaScript">
function validate($)
{
if ($.subject.value==0) {
alert("Select a subject...");
return(false);
} else {
return(true);
}
}
function ShowContent(par1, par2)
{
document.getElementById('category1,category1').style.display = 'none';
document.getElementById('category2,category2').style.display = 'none';
document.getElementById('category3,category3').style.display = 'none';
document.getElementById('category4,category4').style.display = 'none';
document.getElementById('category5,category5').style.display = 'none';
document.getElementById('category6,category6').style.display = 'none';

//Parameter1
if ((par1 == 1) || (par1 == 3) || (par1 == 5) ){
document.getElementById('category1').style.display = 'block';
} else
if (par1 == 8) {
document.getElementById('category4').style.display = 'block';
} else
if (par1 >= 0) {
document.getElementById('category5').style.display = 'block';
}
//Parameter2
if ((par2 == 1) || (par2 == 3) || (par2 == 5) ){
document.getElementById('category1').style.display = 'block';
} else
if (par2 == 8) {
document.getElementById('category4').style.display = 'block';
} else
if (par2 >= 0) {
document.getElementById('category5').style.display = 'block';
}
}
function Submit()
{
document.myform.submit();
}
</script>
<!-- If the viewer has javascript disabled the anchors simply wont work -->

Fotiman

12:49 pm on Jan 23, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



1. Don't include the language attribute on your script tag. It's invalid and hasn't been needed for about 15 years. Also, if your page is HTML5, then you can also remove the type attribute on your script tag, leaving you with just:
<script>

2. The value you're passing to document.getElementById contains a comma. I'm not sure that's valid.