String.concat problem

Ztruker

New member
This is a function that I've used in my web pages for years. It stopped working a few years ago and I never bothered to look at why. Today I finally took the time to debug it and I get a message that says String.concat is not a function. I've done some looking but it's been a long time since I've done any coding of any kind and truthfully I'm lost. I'm looking at PHP manuals and documentation but have not found what I need (yet).

Thanks, Rich K.

// ---------------------------------------------------------------------------
// Make selected text bold, italicized or underlined by adding the appropriate
// HTML tags around the selected text.
// ---------------------------------------------------------------------------
function makeText($char)
{
var $tb = document.getElementById("textinput");
if (document.selection)
{
var str=document.selection.createRange().text;
if (str != '' && str!= 'undefined')
{
var sel=document.selection.createRange();
sel.text="<"+$char+">"+str+"</"+$char+">";
}
}
else if (typeof $tb.selectionStart != 'undefined')
{
var $before, $after, $selection;
if ($tb.selectionStart == 0) // Starts at left edge?
$before = ''; // No before then
else
$before= $tb.value.substring(0, $tb.selectionStart);

$selection = $tb.value.substring($tb.selectionStart, $tb.selectionEnd);
if ($selection != "")
{
if ($tb.selectionEnd == $tb.value.length) // Ends at left edge?
$after = ''; // No after then
else
$after = $tb.value.substring($tb.selectionEnd, $tb.value.length);
$tb.value= String.concat($before, "<"+$char+">", $selection, "</"+$ch+">", $after);
}
}
$tb.focus();
return false;
}
 
This is not a php but javascript issue.
Maybe you are using some library that override the String object. You are using the $ch variable that is defined nowhere, probably you wanted to use the $char variable.

Try to use:
Code:
$tb.value= $before + "<"+$char+">" + $selection +"</"+$ch+">" +$after;
There is also possibility that the text input does nit exists when you run your script, so that may be a reason of the issue
 
Sorry, javascript it is.

For completeness, here is a debug trace of the function. It all looks good but the
Code:
<b>
and
Code:
</b>
never get insterted into the data. What really bugs me is this used to work.

view


view


Agree the variable needed to be $char. I'll take this to a javascript forum for additional help after I spend more time looking at JS help online.

Thank you.

Note:
Tried to embed two screen captures of the debug session. Put them on Google drive but they don't show up here. Where else can I put images so they will be visible here?
 
More testing found that this code works correctly with Seamonkey 2.53.5..1 and older browsers under Windows 7.
Any browser tested so far under Windows 10 or 11 doesn't work.
 
Back
Top