Click to See Complete Forum and Search --> : Appending a delimiter


tomei
02-24-2003, 01:08 AM
Hi,

I need to append a delimiter (e.g. comma) to a textarea after scanning in a serial number to separate a series of serial numbers.

E.g. AE12344555, 12324253424, 23872873SD

function appendcomma(string){
var newstr
newstr = string + ", "
return newstr
}

I've tried using onchange with the above function but the changes can only be seen once focus is out of the textarea. I need to keep the focus on the textarea at all times until all serial numbers are scan.

onKeyUp doesn't work as well. I get A,E,1,2,3,4,4,5,5,5 instead of AE12344555, 12324253424

Can someone help me on this?

khalidali63
02-24-2003, 06:29 AM
I'd say use key event trapping and look for spacebar press ( keycode="32")

and only call the above function when this condition is met.

Just another perspective.

cheers

Khalid

Dan Drillich
02-24-2003, 07:45 AM
To replace the spaces with commas, you can use -


<script>

var org = "AE12344555 12324253424 23872873SD";
var newD = org.replace(/ /g,',');
document.write(newD);

</script>