I found a way to split a string into an array as per How do I split a string, breaking at a particular character?. Unfortunately, this doesn't seem to work when getting the string from a function.
In it, the string is made from a variable.
var input = 'John Smith~123 Street',
array = input.split(/~/);
This would make array[0] = 'John Smith'
and array[1] = '123 Street'
.
When I try make this with a variable from a function, it doesn't work as shown below.
<input type=button onclick="fn('John Smith~123 Street')" value=clickme>
function fn(stringval)
{
var array = stringval.split(/~/);
}
Does anyone know why this happens and how to get out of it? I tried going var input = stringval;
but that didn't work. If you answer, I can use jQuery or Javascript.
Thanks!
EDIT:
This is exactly what it is doing:
<h2 class=opt onclick="tree('Basic Formatting',1,'#html~HTML');">
function tree(i,j,k)
{
var a = k.split(/~/);
if (j==1)
{
$('#path').html('<span onclick="pageLoad(\'.lang\')">Home</span> > '+'<span onclick="pageLoad(\''+a[0]+'\')">'+a[1]+'</span> > '+i);}
}
I am attempting for it to result in:
<div id=path>
<span onclick="pageLoad(\'.lang\')">Home</span>
>
<span onclick="pageLoad(\'#html\')">HTML</span>
> Basic Formatting
</div>