javascript - Unable to print an array of numbers in ascending order when the list is generated -
my code generates matrix of numbers when ok symbol selected. but, want add sorting functionality relist matrix in ascending order when "by result" button selected. suggestions on how can ?
html code
<div class="rightdiv"> <div id = "pastcalcblock"> <h3> past calculations </h3> <input type = "text" size = "1" id = "text1"/> <input type = "text" size = "1" id = "text2"/> <input type = "text" size = "1" id = "text3"/> <input type = "text" size = "1" id = "text4"/><br> <input type = "button" value = "ok" id = "operation" onclick = "display()"/> <div id = "resulttab"> sort<br> <input type = "button" value = "as entered" id = "enteredbut"> <input type = "button" value = "by result" id = "resultbut" onclick() = "sortdisplay()"><br><br> <div id="expressions"> </div> </div> </div>
javascript code
function display() { var arrayone =[document.getelementbyid('text1').value,document.getelementbyid('text2').value,document.getelementbyid('text3').value,document.getelementbyid('text4').value ]; new_array=arrayone.join(" "); var para = document.createelement("p"); var t = document.createtextnode(new_array); para.appendchild(t) document.getelementbyid("expressions").appendchild(para); } function sortdisplay() { function dosort() { var container = document.getelementbyid("expressions"); var elements = container.childnodes; var sortme = []; (var i=0; i<elements.length; i++) { } }
use .textcontent
contents of text node in p
element. split array, sort array, put div.
function sortdisplay() { function dosort() { var container = document.getelementbyid("expressions"); var sortme = container.childnodes[0].textcontent.split(' '); sort(sortme); container.innerhtml = ''; new_array=sortme.join(" "); var para = document.createelement("p"); var t = document.createtextnode(new_array); para.appendchild(t) document.getelementbyid("expressions").appendchild(para); }
Comments
Post a Comment