Simple JavaScript question, Resizing on click.

Posted on 2012-09-20
Last Modified: 2012-09-20

I have put an onclick event on a textarea, and want to expand it and schrink it again when it's clicked.

Can someone explain to me, why this will only expand to 3 lines and not fold back?

onclick="if (this.rows==3){this.rows = 1}; if (this.rows==1){this.rows = 3};"

Question by:NaanPLS
    LVL 4

    Accepted Solution

    Your first if statement triggers if rows=3 and sets rows to 1.  After that triggers, your second if statement sees that rows is = 1 and sets rows=3.

    You'll want to use an if-else statement so after the first if processes it doesn't move on to the next.

    Author Comment

    You are right, what confused me was it actually did execute the second part, rather than the first, when i did:

    onclick="if (this.rows==1){this.rows = 3}; if (this.rows==3){this.rows = 1};"

    Nothing happend at all.

    But as you said:
    onclick="if (this.rows==3){this.rows = 1}; else if (this.rows==1){this.rows = 3};"


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
    Citrix XenApp, Internet Explorer 11 set to Enterprise Mode and using central hosted sites.xml file.
    This Micro Tutorial will demonstrate how to add subdomains to your content reports. This can be very importing in having a site with multiple subdomains.
    Shows how to create a shortcut to site-search Experts Exchange using Google in the Chrome browser. This eliminates the need to type out whenever you want to search the site. Launch the Search Engine Menu: In chrome, via you…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now