I have this code:
document.getElementById('numsco').value = ($.trim(data.nscore));
The value of nscore is 140.25. It displays as:
140 2/8
for sorting purposes, it needs to display as:
140 2/8
Is there a way to force that extra space to go away?
replace(" ", " ") does not work, nor do any of several regex solutions I've found online.
This is not a duplicate of the above question, as I have used that code here:
document.getElementById('numsco').value = ($.trim(data.nscore));
document.getElementById('numsco').value.replace(/\s/g, "");
alert(document.getElementById('numsco').value);
and it returns this:
The problem appears to be related to the way whatever tool is used to display the data does so.
Here is the Razor code:
<td hidden="hidden">@Html.EditorFor(model => model.tblMeasurement.num, new { htmlAttributes = new { @class = "form-control", id = "numsco", @readonly = "readonly", tabindex = "58000", Style = "border-color:none" } })</td>
FOUND A FIX, IF NOT A REAL SOLUTION:
The original coder wrote this monstrosity:
List<tblReglist> reglist = new List<tblReglist>();
var cnty = (from a in be.FIPSCountyCodes
where a.StateCode == 47
select new
{
county = a.CountyName,
countyid = a.CountyCode,
state = a.StateCode
}).ToArray();
var regtbl = (from reg in db.tblReglists
join mes in db.tblMeasurements
on reg.ID equals mes.ID
where reg.IsUsed == true
&& (mes.IsUsed == true)
&& (reg.regeligible == "Y")
&& (mes.IsUsed == true)
//restrictions
&& (reg.weapon.Contains("Bow") && (mes.typ.Contains("Typ") && mes.numScore >= 115)
|| (reg.weapon.Contains("Bow") && (mes.typ.Contains("NonTyp") && mes.numScore >= 140))
|| (reg.weapon.Contains("Muzzleloader") && (mes.typ.Contains("NonTyp") && mes.numScore >= 150))
|| (reg.weapon.Contains("Muzzleloader") && (mes.typ.Contains("Typ") && mes.numScore >= 125))
|| (reg.weapon.Contains("Gun") && (mes.typ.Contains("Typ") && mes.numScore >= 140))
|| (reg.weapon.Contains("Gun") && (mes.typ.Contains("NonTyp") && mes.numScore >= 165)))
orderby mes.numScore descending
select new
{
scored = mes.abtotal8,
type = mes.typ,
weapons = reg.weapon,
county = reg.CountyId,
harvestdate = reg.harvestDate,
frstname = reg.firstName,
lstname = reg.lastName,
nscre = mes.numScore
}).ToArray();
var query = from r in regtbl
join c in cnty
on r.county equals c.countyid
orderby r.nscre descending
select new
{
firstName = r.frstname,
score = r.scored,
typ = r.type,
weapon = r.weapons,
countys = c.county,
harvdate = r.harvestdate,
lstnme = r.lstname
};
foreach (var item in query)
{
reglist.Add(new tblReglist()
{
city = item.score.ToString(),
street = item.typ,
weapon = item.weapon,
state = item.countys,
firstName = item.firstName,
lastName = item.lstnme,
harvestDate = item.harvdate
});
}
return View(reglist);
It's a horrendous mess of spaghetti, but with the help of a couple of coworkers, we followed it through and found that it's something with the way the ToString() function is modifying the value here:
city = item.score.ToString()
Adding
.Replace(" ", " ")
...after the ToString() made it display properly.
I despise working on other programmers' code.