Javascript to split a field value at a certain character

When implementing JavaScript within your SAP BSP you may want to capture an on screen field value, ID or name  and then split this value at a certain character. I.e. if you have the value 00001-345-bob stored in an HTML field with the ID “datafield” you can use the following code to capture this value and split it at the ‘-‘ character.

var fieldvalue = document.getElementById(‘datafield).value;

var fields = fieldvalue.split(/-/);

var value1 = fields[0];

var value2 = fields[1];

var value3 = fields[2];

Leave a Comment

Your email address will not be published. Required fields are marked *