.resize() function for textarea











up vote
1
down vote

favorite












I want to save the height and width of the textarea when the user change it's dimensions.



I've tried to use:



$('textarea').resize(function() {

var height = $('textarea').css('height');

var width = $('textarea').css('width');

$.post('vocabresize.php?height=' + height + '&&width=' + width, function() {});

});


But the $.post() function hasn't been called, so I changed it to:



$('textarea').resize(function() {

$('body').html('Yay it worked');

});


And when I was changing size of textarea the 'Yay it worked' didn't appeared.










share|improve this question









New contributor




Dmitry Khotinskiy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Sorry, I miss-copied
    – Dmitry Khotinskiy
    Nov 12 at 17:36










  • So one code smell is that you are using $.post() without post data. You're sending data with a url query string.
    – Taplar
    Nov 12 at 17:38










  • idownvotedbecau.se/itsnotworking
    – connexo
    Nov 12 at 17:38










  • Possible duplicate of Resize event for textarea?
    – Ian
    Nov 12 at 17:40










  • You also have &&width= which would be an invalid url string
    – Taplar
    Nov 12 at 17:40















up vote
1
down vote

favorite












I want to save the height and width of the textarea when the user change it's dimensions.



I've tried to use:



$('textarea').resize(function() {

var height = $('textarea').css('height');

var width = $('textarea').css('width');

$.post('vocabresize.php?height=' + height + '&&width=' + width, function() {});

});


But the $.post() function hasn't been called, so I changed it to:



$('textarea').resize(function() {

$('body').html('Yay it worked');

});


And when I was changing size of textarea the 'Yay it worked' didn't appeared.










share|improve this question









New contributor




Dmitry Khotinskiy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Sorry, I miss-copied
    – Dmitry Khotinskiy
    Nov 12 at 17:36










  • So one code smell is that you are using $.post() without post data. You're sending data with a url query string.
    – Taplar
    Nov 12 at 17:38










  • idownvotedbecau.se/itsnotworking
    – connexo
    Nov 12 at 17:38










  • Possible duplicate of Resize event for textarea?
    – Ian
    Nov 12 at 17:40










  • You also have &&width= which would be an invalid url string
    – Taplar
    Nov 12 at 17:40













up vote
1
down vote

favorite









up vote
1
down vote

favorite











I want to save the height and width of the textarea when the user change it's dimensions.



I've tried to use:



$('textarea').resize(function() {

var height = $('textarea').css('height');

var width = $('textarea').css('width');

$.post('vocabresize.php?height=' + height + '&&width=' + width, function() {});

});


But the $.post() function hasn't been called, so I changed it to:



$('textarea').resize(function() {

$('body').html('Yay it worked');

});


And when I was changing size of textarea the 'Yay it worked' didn't appeared.










share|improve this question









New contributor




Dmitry Khotinskiy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I want to save the height and width of the textarea when the user change it's dimensions.



I've tried to use:



$('textarea').resize(function() {

var height = $('textarea').css('height');

var width = $('textarea').css('width');

$.post('vocabresize.php?height=' + height + '&&width=' + width, function() {});

});


But the $.post() function hasn't been called, so I changed it to:



$('textarea').resize(function() {

$('body').html('Yay it worked');

});


And when I was changing size of textarea the 'Yay it worked' didn't appeared.







javascript jquery events jquery-events






share|improve this question









New contributor




Dmitry Khotinskiy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Dmitry Khotinskiy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited Nov 12 at 21:17









Ian

1,81631944




1,81631944






New contributor




Dmitry Khotinskiy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Nov 12 at 17:33









Dmitry Khotinskiy

113




113




New contributor




Dmitry Khotinskiy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Dmitry Khotinskiy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Dmitry Khotinskiy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • Sorry, I miss-copied
    – Dmitry Khotinskiy
    Nov 12 at 17:36










  • So one code smell is that you are using $.post() without post data. You're sending data with a url query string.
    – Taplar
    Nov 12 at 17:38










  • idownvotedbecau.se/itsnotworking
    – connexo
    Nov 12 at 17:38










  • Possible duplicate of Resize event for textarea?
    – Ian
    Nov 12 at 17:40










  • You also have &&width= which would be an invalid url string
    – Taplar
    Nov 12 at 17:40


















  • Sorry, I miss-copied
    – Dmitry Khotinskiy
    Nov 12 at 17:36










  • So one code smell is that you are using $.post() without post data. You're sending data with a url query string.
    – Taplar
    Nov 12 at 17:38










  • idownvotedbecau.se/itsnotworking
    – connexo
    Nov 12 at 17:38










  • Possible duplicate of Resize event for textarea?
    – Ian
    Nov 12 at 17:40










  • You also have &&width= which would be an invalid url string
    – Taplar
    Nov 12 at 17:40
















Sorry, I miss-copied
– Dmitry Khotinskiy
Nov 12 at 17:36




Sorry, I miss-copied
– Dmitry Khotinskiy
Nov 12 at 17:36












So one code smell is that you are using $.post() without post data. You're sending data with a url query string.
– Taplar
Nov 12 at 17:38




So one code smell is that you are using $.post() without post data. You're sending data with a url query string.
– Taplar
Nov 12 at 17:38












idownvotedbecau.se/itsnotworking
– connexo
Nov 12 at 17:38




idownvotedbecau.se/itsnotworking
– connexo
Nov 12 at 17:38












Possible duplicate of Resize event for textarea?
– Ian
Nov 12 at 17:40




Possible duplicate of Resize event for textarea?
– Ian
Nov 12 at 17:40












You also have &&width= which would be an invalid url string
– Taplar
Nov 12 at 17:40




You also have &&width= which would be an invalid url string
– Taplar
Nov 12 at 17:40












2 Answers
2






active

oldest

votes

















up vote
1
down vote













textarea doesn't fire a resize event when resized; that is for resizing the window. Instead, you can store the size of the textarea outside the function, and then check for changes when the mouse is released. Something like so would work:



let myTextArea = $('#myTextArea');
let oldHeight = myTextArea.height();
let oldWidth = myTextArea.width();

myTextArea.mouseup(function() {
let newHeight = $(this).height();
let newWidth = $(this).width();
if(newHeight !== oldHeight || newWidth !== oldWidth) {
console.log("Text area was resized!");
oldHeight = newHeight;
oldWidth = newWidth;
}
})


Note that this won't detect when the textarea size changes for other reasons; for example when the window resizes. Also, to make it work for every text area on the page, you'd need to loop through them all and store their dimensions in an object so you could retrieve them.






share|improve this answer




























    up vote
    0
    down vote













    .resize does not work on a textarea element. I've just tested it myself. You can do this ;)



    var textareaWidth;
    var textareaHeight;
    $('textarea').mouseup(function(evt) {
    if(this.clientWidth != textareaWidth || this.clientHeight != textareaHeight) {
    console.log(`new size= ${this.clientWidth} x ${this.clientHeight}`);
    textareaWidth = this.clientWidth;
    textareaHeight = this.clientHeight;
    }
    });





    share|improve this answer























    • @Taplar I mean .resize() does not work on a textarea element.
      – Frank Roth
      Nov 12 at 17:47










    • I've fixed it with two helper variables.
      – Frank Roth
      Nov 12 at 17:54











    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });






    Dmitry Khotinskiy is a new contributor. Be nice, and check out our Code of Conduct.










     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53267288%2fresize-function-for-textarea%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote













    textarea doesn't fire a resize event when resized; that is for resizing the window. Instead, you can store the size of the textarea outside the function, and then check for changes when the mouse is released. Something like so would work:



    let myTextArea = $('#myTextArea');
    let oldHeight = myTextArea.height();
    let oldWidth = myTextArea.width();

    myTextArea.mouseup(function() {
    let newHeight = $(this).height();
    let newWidth = $(this).width();
    if(newHeight !== oldHeight || newWidth !== oldWidth) {
    console.log("Text area was resized!");
    oldHeight = newHeight;
    oldWidth = newWidth;
    }
    })


    Note that this won't detect when the textarea size changes for other reasons; for example when the window resizes. Also, to make it work for every text area on the page, you'd need to loop through them all and store their dimensions in an object so you could retrieve them.






    share|improve this answer

























      up vote
      1
      down vote













      textarea doesn't fire a resize event when resized; that is for resizing the window. Instead, you can store the size of the textarea outside the function, and then check for changes when the mouse is released. Something like so would work:



      let myTextArea = $('#myTextArea');
      let oldHeight = myTextArea.height();
      let oldWidth = myTextArea.width();

      myTextArea.mouseup(function() {
      let newHeight = $(this).height();
      let newWidth = $(this).width();
      if(newHeight !== oldHeight || newWidth !== oldWidth) {
      console.log("Text area was resized!");
      oldHeight = newHeight;
      oldWidth = newWidth;
      }
      })


      Note that this won't detect when the textarea size changes for other reasons; for example when the window resizes. Also, to make it work for every text area on the page, you'd need to loop through them all and store their dimensions in an object so you could retrieve them.






      share|improve this answer























        up vote
        1
        down vote










        up vote
        1
        down vote









        textarea doesn't fire a resize event when resized; that is for resizing the window. Instead, you can store the size of the textarea outside the function, and then check for changes when the mouse is released. Something like so would work:



        let myTextArea = $('#myTextArea');
        let oldHeight = myTextArea.height();
        let oldWidth = myTextArea.width();

        myTextArea.mouseup(function() {
        let newHeight = $(this).height();
        let newWidth = $(this).width();
        if(newHeight !== oldHeight || newWidth !== oldWidth) {
        console.log("Text area was resized!");
        oldHeight = newHeight;
        oldWidth = newWidth;
        }
        })


        Note that this won't detect when the textarea size changes for other reasons; for example when the window resizes. Also, to make it work for every text area on the page, you'd need to loop through them all and store their dimensions in an object so you could retrieve them.






        share|improve this answer












        textarea doesn't fire a resize event when resized; that is for resizing the window. Instead, you can store the size of the textarea outside the function, and then check for changes when the mouse is released. Something like so would work:



        let myTextArea = $('#myTextArea');
        let oldHeight = myTextArea.height();
        let oldWidth = myTextArea.width();

        myTextArea.mouseup(function() {
        let newHeight = $(this).height();
        let newWidth = $(this).width();
        if(newHeight !== oldHeight || newWidth !== oldWidth) {
        console.log("Text area was resized!");
        oldHeight = newHeight;
        oldWidth = newWidth;
        }
        })


        Note that this won't detect when the textarea size changes for other reasons; for example when the window resizes. Also, to make it work for every text area on the page, you'd need to loop through them all and store their dimensions in an object so you could retrieve them.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 12 at 17:51









        Ian

        1,81631944




        1,81631944
























            up vote
            0
            down vote













            .resize does not work on a textarea element. I've just tested it myself. You can do this ;)



            var textareaWidth;
            var textareaHeight;
            $('textarea').mouseup(function(evt) {
            if(this.clientWidth != textareaWidth || this.clientHeight != textareaHeight) {
            console.log(`new size= ${this.clientWidth} x ${this.clientHeight}`);
            textareaWidth = this.clientWidth;
            textareaHeight = this.clientHeight;
            }
            });





            share|improve this answer























            • @Taplar I mean .resize() does not work on a textarea element.
              – Frank Roth
              Nov 12 at 17:47










            • I've fixed it with two helper variables.
              – Frank Roth
              Nov 12 at 17:54















            up vote
            0
            down vote













            .resize does not work on a textarea element. I've just tested it myself. You can do this ;)



            var textareaWidth;
            var textareaHeight;
            $('textarea').mouseup(function(evt) {
            if(this.clientWidth != textareaWidth || this.clientHeight != textareaHeight) {
            console.log(`new size= ${this.clientWidth} x ${this.clientHeight}`);
            textareaWidth = this.clientWidth;
            textareaHeight = this.clientHeight;
            }
            });





            share|improve this answer























            • @Taplar I mean .resize() does not work on a textarea element.
              – Frank Roth
              Nov 12 at 17:47










            • I've fixed it with two helper variables.
              – Frank Roth
              Nov 12 at 17:54













            up vote
            0
            down vote










            up vote
            0
            down vote









            .resize does not work on a textarea element. I've just tested it myself. You can do this ;)



            var textareaWidth;
            var textareaHeight;
            $('textarea').mouseup(function(evt) {
            if(this.clientWidth != textareaWidth || this.clientHeight != textareaHeight) {
            console.log(`new size= ${this.clientWidth} x ${this.clientHeight}`);
            textareaWidth = this.clientWidth;
            textareaHeight = this.clientHeight;
            }
            });





            share|improve this answer














            .resize does not work on a textarea element. I've just tested it myself. You can do this ;)



            var textareaWidth;
            var textareaHeight;
            $('textarea').mouseup(function(evt) {
            if(this.clientWidth != textareaWidth || this.clientHeight != textareaHeight) {
            console.log(`new size= ${this.clientWidth} x ${this.clientHeight}`);
            textareaWidth = this.clientWidth;
            textareaHeight = this.clientHeight;
            }
            });






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 12 at 17:54

























            answered Nov 12 at 17:45









            Frank Roth

            2,99721624




            2,99721624












            • @Taplar I mean .resize() does not work on a textarea element.
              – Frank Roth
              Nov 12 at 17:47










            • I've fixed it with two helper variables.
              – Frank Roth
              Nov 12 at 17:54


















            • @Taplar I mean .resize() does not work on a textarea element.
              – Frank Roth
              Nov 12 at 17:47










            • I've fixed it with two helper variables.
              – Frank Roth
              Nov 12 at 17:54
















            @Taplar I mean .resize() does not work on a textarea element.
            – Frank Roth
            Nov 12 at 17:47




            @Taplar I mean .resize() does not work on a textarea element.
            – Frank Roth
            Nov 12 at 17:47












            I've fixed it with two helper variables.
            – Frank Roth
            Nov 12 at 17:54




            I've fixed it with two helper variables.
            – Frank Roth
            Nov 12 at 17:54










            Dmitry Khotinskiy is a new contributor. Be nice, and check out our Code of Conduct.










             

            draft saved


            draft discarded


















            Dmitry Khotinskiy is a new contributor. Be nice, and check out our Code of Conduct.













            Dmitry Khotinskiy is a new contributor. Be nice, and check out our Code of Conduct.












            Dmitry Khotinskiy is a new contributor. Be nice, and check out our Code of Conduct.















             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53267288%2fresize-function-for-textarea%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            mysqli_query(): Empty query in /home/lucindabrummitt/public_html/blog/wp-includes/wp-db.php on line 1924

            How to change which sound is reproduced for terminal bell?

            Can I use Tabulator js library in my java Spring + Thymeleaf project?