Trying to use jquery to output a string that contains a hyphen like so:
$("#OpsContent").html($("#OpsContent").html() + "<b>" + $(this).text() +
+ ( ( group ) ? " for <u>" + group + "</u>" : "" )
+ " to</b> " + choices + "<br />");
Unfortunately if the string “group” contains a hyphen, the output always appears as:
<b>Set Group Rank<u>NaN</u> to</b> 5
I can’t seem to get the group variable to be correctly interpretted as a string, it seems rather like it is trying to subtract the two halves of the string. I have tried using group = group.replace("-", "."); and "\-" before the line in question, but it doesn’t help. Even stranger is the fact that a line immediately after works fine:
OpsPending[ count ] = "?do=" + String($(this).attr("id"))
+ "&selection=" + choices
+ ( ( group ) ? "&group=" + group : "" );
outputs to the variable perfectly well!
A solution would be to go back and pre-process all the hyphens in the page with php, but that seems unnecessarily complicated: there should be a better way than this.
Hm, you seem to have an extra
+in your string concatenation (right before the parenthesized ternary operator), which would cause the part where you are using the ternary operator to be converted from a string to a number since that extra+would be interpreted as a unary plus operator, resulting in NaN. Although that doesn’t exactly explain your symptons (i.e. it only occuring whengrouphas a hyphen, and actually only havinggroupappearing as NaN, not the entire ternary expression), I can’t see how your code example would work correctly without removing the extra+there