Solved

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

Posted on 2014-10-14
3
107 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to use question mark (?) in filename with html 25 73
Asp in script 6 39
Override MS CSS in SharePoint Online Modal Form 19 46
How do I show metrics with PHP or Javascript 6 34
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar 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)

828 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