Currently, the script is capable of calculating the width of the script based on user input and can also determine the width of a string. However, I am facing an issue when attempting to repeat a string entered by the user. For example, if the user inputs "A" and then repeats it 6 times resulting in "AAAAAA", that's where the problem arises. The function created for repeating the string is not functioning as intended. Essentially, the goal is to repeat the string a certain number of times and then calculate its width. Any suggestions on how to resolve this issue?
$.fn.textWidth = function(text, font) {
var fontsize = $('#fntSize').val();
if (!$.fn.textWidth.fakeEl) $.fn.textWidth.fakeEl = $('<span>').hide().appendTo(document.body);
$.fn.textWidth.fakeEl.text(text || this.val() || this.text()).css({'font-size':fontsize+'px'});
return $.fn.textWidth.fakeEl.width();
};
$.fn.repeat = function( num )
{
return new Array( num + 1 ).join( this );
}
$("[name='txtLine[]']").each(function(){
$(this).css({"background-color":"#fff"}).siblings('span.errorMsg').text('');;
if (!this.value.length)
{
$(this).focus();
$(this).css({"background-color":"#f6d9d4"}).siblings('span.errorMsg').text('Please add a word.');
event.preventDefault();
}
if($(this).repeat(6).textWidth() >= 490)
{
alert("Too long");
event.preventDefault();
}
});
});