2

as I said I wanted to add onmousedown or onclick in select tag so that when I select an option from select tag, it'll fire up a function which will make visibility to another html tag, like a div tag! I used css to make the div tag's visibility to none! When the relevant option is clicked, I want to show up that div tag in my page but it doesn't work the way I want! I think, the code and a screen shot might help you guys to detect what I am not getting right in the code! Please, help me in this regard!

<html>
<head>
<title>Something</title>
</head>
<body>
<script>
function mouseDown(){
    var element1 = document.getElementById("Nl").value;
    var element2 = document.getElementById("bld").value;
    var element3 = document.getElementById("hspt").value;
    var changing = document.getElementById("Hp");
    var changingV2 = document.getElementById("BB");

    if(element3 == "Hospitals"){
        changing.style.display = "block";
        changingV2.style.display = "none";  
    }
    if(element2 == "bloodBanks"){
        changing.style.display = "none";
        changingV2.style.display = "block";
    }
    /*else
    document.write("nothing should happen!");*/
}
</script>
<select id = "cate">
    <option id = "Nl" value = "" onclick = "ClickToChange()"></option>
    <option id = "hspt" value = "Hospitals" onclick = "ClickToChange()">Hospital</option>
    <option id = "bld" value = "bloodBanks" onclick = "ClickToChange()">Blood Bank</option>

</select>
<br>
<br>
<br>
<br>
<div id = "Hp" style = "display:none">
    <div>Hospital</div>
    <input id = "hosital" type = "text" maxlength = "40">
</div>
<div id = "BB" style = "display:none">
    <div>Blood Banks</div>
    <input id = "bloodbank" type = "text" maxlength = "40">
</div>

</body>
</html>
  • This was a well-asked question. You have done a good job describing your desired result, as well as posting concise code. Hopefully the answer now linked to your question will provide the solution you’re looking for. Welcome to StackOverflow! – James Hill Sep 09 '14 at 07:04
  • 1
    @JamesHill thanks for showing me the right question and I got my answer! :D and should i delete as it seemed duplicate of another question? – Battle Neurosis Sep 09 '14 at 07:19
  • No need to delete. All is well :-) – James Hill Sep 09 '14 at 17:36

0 Answers0