Learn how to create substrings of other strings with jQuery.
var $someText = $('#name').val(); // Let's say this gets the value 'James Bubb' var firstName = $someText.substr(0,5); // firstName now has the value 'James' var secondName = $someText.substr(6,4) // secondName now has the value 'Bubb'
var $someText = $('#name').val(); // Let's say this gets the value 'James Bubb' var firstName = $someText.substr(0,5); // firstName now has the value 'James' var secondName = $someText.substr(6,10) // secondName now has the value 'Bubb'
Did you spot the differenence? Whereas the second parameter of substr is the length of the sub string you want to return, with substring the second parameter is the end point. Therefore, when getting the secondName we need to specify the the point at which the string ends.
Use either substr or substring with a jQuery reference to achieve a jQuery substring.
$someText.substr(start, length) $someText.substring(start, end)