html - Getting text of checked checkbox in JavaScript -
i having difficulties when trying text of checkbox using javascript. here code html:
content += "<tr><td><input id='type_select1' class=\"pss\" type=\"checkbox\" onclick='querypss()' >commercial , residential</td><td><input id='type_select2' class=\"pss\" type=\"checkbox\" onclick='querypss()' >commercial</td></tr>"; content += "<tr><td><input id='type_select3' class=\"pss\" type=\"checkbox\" onclick='querypss()'>heavy vehicle park</td><td><input id='type_select4' class=\"pss\" type=\"checkbox\" onclick='querypss()'>hospital</td></tr>"; content += "<tr><td><input id='type_select5' class=\"pss\" type=\"checkbox\" onclick='querypss()'>hotel</td><td><input id='type_select6' class=\"pss\" type=\"checkbox\" onclick='querypss()'>industrial</td></tr>"; content += "<tr><td><input id='type_select7' class=\"pss\" type=\"checkbox\" onclick='querypss()'>industrial-white</td><td><input id='type_select8' class=\"pss\" type=\"checkbox\" onclick='querypss()'>office</td></tr>"; content += "<tr><td><input id='type_select9' class=\"pss\" type=\"checkbox\" onclick='querypss()'>recreation</td><td><input id='type_select10' class=\"pss\" type=\"checkbox\" onclick='querypss()'>residential (landed)</td></tr>"; content += "<tr><td><input id='type_select11' class=\"pss\" type=\"checkbox\" onclick='querypss()'>residential (non-landed)</td><td><input id='type_select12' class=\"pss\" type=\"checkbox\" onclick='querypss()'>residential</td></tr>"; content += "<tr><td><input id='type_select13' class=\"pss\" type=\"checkbox\" onclick='querypss()'>white site</td></tr>"; and here how text of checked checkbox:
var type_select = document.getelementbyid('type_select'); if(type_select.checked == true) { var type_filter = type_select.text; alert(type_filter); } however, when check check box, pop message display "undefined". wonder went wrong. in advance.
so trying do. begin lets consider 1 sample content string.
<td><input class=\"pss\" type=\"checkbox\" onclick='querypss()' value = "myvalue">commercial , residential</td> we still have different ids. on click fire customfunction(can querypss) this. make sure add value attribute , set required value.
onclick = customfunction(this) somewhere down, define function this,
function customfucntion(idvalue){ var elem = idvalue.value; } thats it. should work.
Comments
Post a Comment