javascript - Getting values of ul into variable which are not hidden -
i have code:
<div> john<input type="checkbox" onchange="javascript:hideshow(document.getelementbyid(this.value),this)" value="value1" checked="true"> jhonny<input type="checkbox" onchange="javascript:hideshow(document.getelementbyid(this.value),this)" value="value2" checked="true"> jack<input type="checkbox" onchange="javascript:hideshow(document.getelementbyid(this.value),this)" value="value3" checked="true"> </div> <ul id="numeric"> <li id="value1" data-value="info1"> <div id="info1" contenteditable="true">john</div> </li> <li id="value2" data-value="info2"> <div id="info2" contenteditable="true">jhonny</div> </li> <li id="value3" data-value="info3"> <div id="info3" contenteditable="true">jack</div> </li> </ul> <input type="submit" id="send1" value="save" class="button" onclick="action()">
and script:
function hideshow(e, ev) { if (ev.checked) { e.style.display = "block"; } else { e.style.display = "none"; } } function action() { var values = $('#numeric li').map(function () { return $(this).attr('data-value'); }); $lis = $("#numeric li").length; var n = $lis; var a=""; ($i = 0; $i < n; $i = $i + 1) { = (a + (document.getelementbyid((values[$i])).innerhtml) +". "); } alert (a); }
the output : this
here check boxes linked list items in ul. checking/unchecking them hides/shows respective list item. thing list items editable. in code draggable. when click save list items concatenated , saved in variable along changes made in them.
the thing missing when hide list item(i.e. uncheck it) shoudnt concatenated in variable.
ex: if uncheck items variable should empty. here if hidden variable consists values.
i dont know how it. can me. thank you
you're not checking if elements visible in action()
. try like:
function action() { var = ''; $('#numeric li:visible').each(function(index) { += $.trim($(this).text()) + '. '; }); alert(a); }
(i took liberty of simplifying of surrounding code too.)
you can rid of data-value
attributes too, we're not using them anymore.
Comments
Post a Comment