Solved

how to increment an onclick argument or is it a parameter?

Posted on 2014-10-14
3
105 Views
Last Modified: 2014-10-14
In my html, if I have:

<script>var index = 1</script>
 <input type="button" value="Add One" onclick="addOneFunction(index)">

how can I increment the index value by 1 each time the button is clicked?
0
Comment
Question by:Gary Samuels
  • 2
3 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 40380405
<input type="button" value="Add One" onclick="addOneFunction(++index)">

or

<input type="button" value="Add One" onclick="addOneFunction(index++)">
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 40380409
I think you want the second which add 1 after passing it, not before
0
 

Author Closing Comment

by:Gary Samuels
ID: 40380425
Thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

911 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

23 Experts available now in Live!

Get 1:1 Help Now