Javascript to split a field value at a certain character

Advertisements

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.

Advertisements

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

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

Advertisements

var value1 = fields[0];

Advertisements

var value2 = fields[1];

Advertisements

var value3 = fields[2];

Advertisements

Leave a Comment: