You're quite right, Simon: your single line
var len = fn.value.length + fn.value.match(/\//g).length;
does precisely what my awkward two lines did.
While this counts perfectly once a '/' enters the textbox, it unfortunately does no counting till it sees one.
Since the original line
var len = fn.value.length;
by itself counts perfectly when the box has no '/' (i.e. it doesn't know to double for the forward slash), it makes me wonder if an if - else statement might work? Something (that I am clueless how to properly write) sort of like this:
var str= value // This needs to be whatever's in the text box var pos=str.IndexOf("\/") if (pos>=0) { var len = fn.value.length + fn.value.match(/\//g).length; } else { var len = fn.value.length }
Could something like this possibly work? If so, my problem is to get it to read whatever is entered in the box into str. Users will often enter text that has no URL or, most often, a URL at the very end, so they'll want the counter to be keeping a tally from the start even if it doesn't see a slash.
Ok, this looks like it might be that the match(...) actually returns a null value if no match is found, and the length of a null is probably a null, and adding a null to the original length might give a null or zero, which could explain the problem.
So, your latest approach looks promising, however the slash in the IndexOf shouldn't need escaping, …