[Last Call] Learn how to a build a cloud-first strategyRegister Now


Simple JavaScript question, Resizing on click.

Posted on 2012-09-20
Medium Priority
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

Accepted Solution

DustinKikuchi earned 1000 total points
ID: 38417821
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

ID: 38417850
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};"


Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
This Micro Tutorial will demonstrate how nuggets on the Web are formatted by using Chrome Developer Tools. These tools would not only view the site's CSS but it can also modify it and save the CSS to use on your own site.
Suggested Courses

831 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