从PHP加载值时textareas的autosize.js中的错误

I am trying to create a web-form that has the option to reload previously saved data.

The problem is that when a large string of text that was entered into an autosized textarea has been saved and reloaded it adds a large amount of white space to the text area. [See before save, and after load pictures below]

BEFORE SAVE:

BEFORE SAVE

AFTER LOAD:

AFTER LOAD

The form data is loaded by PHP injection of the value as in the following example:

<textarea class='animated' name="courseTitle" id="courseTitle"><?PHP echo ($_POST['courseTitle']) ?></textarea>

The form can be seen in this link. http://pansycheung.com/forms/NewCourseProposal.php?C2EF=0

and data can be loaded into the form in the table below (found at the bottom of the form page).

LOAD TABLE:

LOAD TABLE

SELECT THE FIRST FILE TO LOAD

"Phillip Test EECS3603"

The white space disappears when doing one of the following.

  • Type something into the test area
  • Or adjusting the zoom in the browser

Any help with debugging suggestions would be fantastic.

go to ttp://pansycheung.com/forms/NewCourseProposal.php?C2EF=0 to test the form.

THANK YOU!!!

I don't know if this works, but you can TRIM the value of the textarea with trim(). TRIM

You can also use this function in jquery, if this is necessary.

Using jQuery, did you try 'triggering' the autosize?

$('#courseTitle').trigger('autosize.resize');

You initially have to initialize the autosize;

$('#courseTitle').autosize();

If that still doesn't work try putting the 'trigger' autosize in a setTimeOut();

setTimeout(function(){ 
    $('#courseTitle').trigger('autosize.resize');
}, 1000);