Ask your JavaScript questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

add a push record to toSort and then use ratingSort() JavaScript

  • REFUNDED

https://verlager.com/farhadi.php?box=10 Click green PLUS sign to a few records.


<script>
function add_list() {// Supposed to add a push record to toSort and then use ratingSort() to display the sorted list but it doesn't work

var moniker_name = document.getElementById("wood").value;
if (!moniker_name) {return;}
var moniker_rate = document.getElementById("chuck").value;
var nameValue = moniker_name + " " +moniker_rate;

toSort.push({
name: moniker_name,
rate: moniker_rate
}
);



toSort.sort(function(a, b){ return b.rate - a.rate;});
limit = toSort.length;

var ul = document.getElementById("sortable_1");
var li = document.createElement("li");
li.setAttribute("id", "I" +(limit-1));
li.setAttribute("draggable", "true");
ul.appendChild(li);
document.getElementById("ex2").reset();

ratingSort();

}
</script>


<!--SORT BY RATING -->

<script>

function ratingSort() { $("li").css("border-color", "black");

for (i = 0; i <= limit;) {

var fullRating = toSort[i].rate;

var Name = toSort[i].name.split(" "); var lastName = Name[0]; var firstName = Name[1];

var xLS = lastName.length; var xFS = firstName.length; var xTT = xLS + xFS;

if (xTT > 16) {xFS = 15 - xLS; a_pip = ".";} else {xFS = 99; a_pip = "";}

//var displayName = lastName.substr( 0, 18) +" " + firstName.substr( 0, xFS) + a_pip + " " + toSort[i].rate;
var displayName = lastName +" " + firstName.substr( 0, 12) + " " + toSort[i].rate;

$("#I" + (i)).text(displayName);
colorize($("#I" + (i)), toSort[i].rate);

i++;}

}

</script>

HTML FORM:
<form action="javascript:add_list()" method="post" name="late_to_party" class="modal" id="ex2" autocomplete="off" style="display:none; background:lightgreen; width:40rem; padding:2.5rem">
<fieldset>

<label style = "font-size:1.5rem; width:10rem; float:left">Last, First</label>
<input type="text" maxlength = "25" size = "20" name="name" id="wood" style = "text-transform: capitalize; font-size:1.8rem; width:25rem; float:left" autofocus />

<br />

<label style = "font-size:1.5rem; width:8rem; clear:both; float:left; margin-left:2rem; margin-top:2rem">Rating</label>
<input type="text" maxlength = "4" size = "4" id="chuck" style = "width:8rem; font-size:1.8rem;float:left; margin-top:2rem"><br />

<input type="submit" style = "margin-top:2rem; font-size:2rem" value="Add a new player" />
</fieldset>
</form>

Answers (0)

No answers yet.