[javascript] JavaScript code for getting the selected value from a combo box

Can any one give me a sample code that gets the selected value from an existing combo box?

I have this code but its not doing anything:

function check () 
{
    var e = document.getElementById("ticket_category_clone");
    var str = e.options[e.selectedIndex].text;

    alert(str);

    if (str==="Hardware")
    {
        SPICEWORKS.utils.addStyle('#ticket_c_hardware_clone{display: none !important;}');
    }       
}

SPICEWORKS.app.helpdesk.ready(check);?

heres a img of the code

and the code

<select id="ticket_category_clone" name="ticket[category]" hdpp="ticket_category">
<option value=""></option><option value="Hardware">Hardware</option>
<option value="Software">Software</option>
<option value="Rede" selected="selected">Rede</option>
<option value="Pedidos">Pedidos</option>
<option value="Formação/Dúvida">Formação/Dúvida</option>
<option value="Outro">Outro</option><option value="#edit_categories#">Edit Categories...</option></select>

what i want its find a way to get the selected value fo that combobox

This question is related to javascript combobox

The answer is


I use this

var e = document.getElementById('ticket_category_clone').value;

Notice that you don't need the '#' character in javascript.

    function check () {

    var str = document.getElementById('ticket_category_clone').value;

      if (str==="Hardware")
      {
        SPICEWORKS.utils.addStyle('#ticket_c_hardware_clone{display: none !important;}');
      }

    }

SPICEWORKS.app.helpdesk.ready(check);?

It probably is the # sign like tho others have mentioned because this appears to work just fine.

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>

</head>
<body>

    <select id="#ticket_category_clone">
  <option value="hw">Hardware</option>
  <option>fsdf</option>
  <option>sfsd</option>
  <option>sdfs</option>
</select>
<script type="text/javascript">
    (function check() {
        var e = document.getElementById("#ticket_category_clone");
        var str = e.options[e.selectedIndex].text;

        alert(str);
        if (str === "Hardware") { 
            alert('Hi'); 
        }


    })();
</script>
</body>