0

i want to get the value of this td

my code

 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); 

and bang it does Nothing, what could be the problem?

the html srry for not post it in the begging

 <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>
4

3 回答 3

0

You could use

var e = document.getElementById("td.body-c_hardware.cell-c_hardware");
var str = e.innerHTML;
于 2012-04-05T15:13:21.700 回答
0

To use getElementById, your tag needs an id

<table>
  <tr><td id="idValue">Content</td></tr>
</table>

and you need to fetch it by just using the id value

document.getElementById('idValue');

If you want to use CSS-like selectors, you may be best using a toolkit like jQuery

jQuery('#idValue');
jQuery('td.className');
jQuery('table.tableClass td.cellClass');
于 2012-04-05T15:18:38.313 回答
0

You need to get the select element by its id. You can then access either the text of the option or the value of the option. I think you may want the value instead of the text. I have posted a solution for both ways.

http://jsfiddle.net/c4eWg/1

var e = document.getElementById('ticket_category_clone');
alert(e.options[e.selectedIndex].innerHTML);

​ If you want the actual value, and not the text then use this instead. I suspect it might be what you want.

var e = document.getElementById('ticket_category_clone');
alert(e.value);
于 2012-04-05T15:18:56.467 回答