问题描述:

I've made two js files having 1 function each . 1>> Resizing textarea based on content having code

function autosizeTextArea(textArea)

{

while (textArea.rows > 1 && textArea.scrollHeight < textArea.offsetHeight){

textArea.rows--;

}

while (textArea.scrollHeight > textArea.offsetHeight){

textArea.rows++;

}

//textArea.rows++

}

2>> Code to add space after comma

function formatEmailAddress(textarea,event)

{

var text = textarea.value;

event = event||window.event;

if(event.ctrlKey && event.keyCode==86)

{

textarea.value = formatText(text,",",", ");

}

else if(text.charAt(text.length-1)==",")

{

textarea.value = text+" ";

}

//textarea.scrollHeight = textarea.value/textarea.cols;

return textarea;

}

function formatText(text, replacedText, replacementText)

{

var textArray = text.split(replacedText);

var formattedString = textArray[0].trim();

for(i=1;i<textArray.length;i++)

{

formattedString = replacementText+textArray[i].trim();

}

return formattedString;

}

Problem:: What I want to achieve is when I Ctrl+v data in textarea first it should format content then resize the text area. On main jsp I called script::

<script type="text/javascript">

function resizeTextArea(textArea)

{

textArea = formatEmailAddress(textArea);

autosizeTextArea(textArea);

}

</script>

both functions formatEmailAddress and autosizeTextArea works fine when i type into textarea, also autosizeTextArea works fine on all events like typing , paste ,cut when called alone. But when I'm trying to ctrl+v when both function are called, auto resizing of textarea doesn't occurs. Please help me out...

相关阅读:
Top