Dropdowns should show each div - but don't...

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Dropdowns should show each div - but don't...

Post by simonmlewis »

Code: Select all

<script>
function updateSelect(obj){
    div = document.getElementById("salt");
    if(obj.options[obj.selectedIndex].value == "PLEASE PAINT"){
        if(div.style.display == "none")
            div.style.display = "inline";
    }else{
        div.style.display = "none";
        document.getElementById("salti").value = "";
    }
    
    
    div = document.getElementById("short");
    if(obj.options[obj.selectedIndex].value == "SHORT"){
        if(div.style.display == "none")
            div.style.display = "inline";
    }else{
        div.style.display = "none";
        document.getElementById("salti").value = "";
    }
    
}
</script>
-
-
-
-
-
echo "
<select name='itemname2' onchange=\"updateSelect(this)\">
<option value='0'>PLEASE SELECT</option>
<option value='SHORT'>SHORT</option>
<option value='MEMBER'>SITE MEMBER</option>
<option value='PLEASE PAINT'>PLEASE PAINT</option>
</select>

<div id='salt' style='display:none; font-size: 12px'><div class='usercommentsform' style='margin-top: 0px; margin-bottom: 4px; background-color: #ffffff;'>
text will be here for paint</div>
</div></div>


<div id='short' style='display:none; font-size: 12px'>
<div class='usercommentsform' style='margin-top: 0px; margin-bottom: 4px; background-color: #ffffff;	background-image: url(/images/bg_paintedprice.png); background-repeat: repeat-x;'>
text will be here for short
</div>
</div>

I need each separate dropdown selection to make these DIVs appear. It works for "salt" but not for "short".

I am sure it is how I am using the salt word, in the SCRIPT at the top. Any ideas?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
avibitton
Forum Newbie
Posts: 18
Joined: Sat Jul 14, 2012 4:35 pm

Re: Dropdowns should show each div - but don't...

Post by avibitton »

look what i wrote at the comment . scroll down
div = document.getElementById("short");
if(obj.options[obj.selectedIndex].value == "SHORT"){
if(div.style.display == "none")
div.style.display = "inline";
}else{
div.style.display = "none";
document.getElementById("salti").value = ""; ----------------------- ------------------> it shouldnt be here short instead of salti ? cause like that your not canceling the display none
}

}
</script>


good luck Avi .
Post Reply