I’m stuck with this task:
I have a function attached with onclick=”myFunction(this);” to tens of images of my page.
Inside the function I retrieve the class name of the clicked image.
Lastly I would like to look inside a html form and modify an input field with the same id as the retrieved class.
Here is an example to clarify:
- User clicks on image with class=”green”
- We find the input field of a form with the id=”green” and change it’s value to 1
or
- User clicks on image with class=”red”
- We find the input field of a form with the id=red” and change it’s value to 1
and so on..
I have most of the code but what I dont seem to get is how I should use the retrieved class of an image to find a corresponding id in the form.
you can concatenate the class name with
#sign and select the input tag: