- This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
Viewing 3 posts - 1 through 3 (of 3 total)
- The forum ‘JavaScript’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Home › Forums › JavaScript › 3 buttons created using JavaScript, need to update 3 text boxes with each click
I am just learning JavaScript and I might say, it is tough for me.
I created 3 buttons to be used in a little survey for a webpage and each button has a text box where with each button click, the number in the text box increases by one.
I tried so many things without the correct outcome.
When I click on the first button, the text box increases by one; but, it also increases when I click on the other buttons.
I tried using one function and also tried to use a switch(this.id) for the 3 cases (I saw something similar to this in the “Visual Quickstart Guide” book.
I only have the function written out for only the “friend” button and not the other 3.
Also, when I refresh my browser window, the text box reverts back to the default value of 0. How do you set it so it does not refresh to 0?
I attached my code (hopefully it shows up).
If someone would point me in the right direction, I would appreciate it.
Thanks.
Edit: This link to my CodePen did not show the code. I will see if there is a way to show the code.
Edit2: Oh, there is an “edit this pen” in the lower left (I have not used CodePen very much either.
You could pass an argument to your function and based on that determine what field gets to be affected.
http://codepen.io/alenabdula/pen/vDtpf/
In this example, I’m passing in the ID of the input.
Hope that helps,
-Alen
Hi Alen
Thanks, that worked.