Question

I have this function and I want to make the var category to have the value of the combobox that has the id #ticket_category_clone

What am I doing wrong?

   function check () {
      var category="#ticket_category_clone";
          if (category=="Hardware")
      {
      SPICEWORKS.utils.addStyle('#ticket_c_hardware_clone{display: none !important;}');
      }
    }

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

edit

It only alerts if I make the code this way:

function check () {
    // var category = document.getElementById('#ticket_c_hardware_clone').value;
   var category ="Hardware";
   alert(category)
          if (category=="Hardware")
      {
        SPICEWORKS.utils.addStyle('#ticket_c_hardware_clone{display: none !important;}');


      }
   alert(category)
    }

SPICEWORKS.app.helpdesk.ready(check);

like this? http://img12.imageshack.us/img12/8438/semttuloluu.png

and the code:

<select id="ticket_category_clone" name="ticket[category]" hdpp="ticket_category"><option value=""></option>
Was it helpful?

Solution

Dunno about spiceworks but in JavaScript that's how you can do that:

var category = document.getElementById("ticket_category_clone").value;

If the # is part of the id, add it as well but note it's not valid ID:

var category = document.getElementById("#ticket_category_clone").value;

Looks like you need some debugging. Try the following code:

var category = "";
var ddl = document.getElementById("ticket_category_clone");
if (ddl) {
    alert("found (1)");
    category = ddl.value;
} else {
    ddl = document.getElementById("#ticket_category_clone");
    if (ddl) {
        alert("found (2)");
        category = ddl.value;
    } else {
        alert("element can't be found");
    }
}
alert(category);

What alerts you get?

OTHER TIPS

Can you test with this lines?

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

alert(str), if you get the value you want?

This addition is probably late but if someone stumble on this they should know that SpiceWorks uses prototype.js as the JavaScript library. Therefore to get an element in the DOM you use the $ sign

So in order to get the combobox you use the following syntax

var e = $("#ticket_category_clone");
var category = e.options[e.selectedIndex].text;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top