JSFiddle - React, Tailwind, and code Playground
HTML
<input id='test' size='40' value='No comma and it fails'>
<input type='button' value='Get Text Before Comma' onclick='javascript:getTextBeforeComma()'>
JavaScript
function getTextBeforeComma()
{
var text = document.getElementById('test').value;
alert("Text: " + text + "\r\nText Before Comma:" + text.substring(0, text.indexOf(',')));
}