I have a jsfiddle application below:
If you open the jsfiddle, you will see a top control which contains “Answer” buttons. You will also see some letter buttons, a “True” button, and a “False” button.
The “True” and “False” buttons work perfectly, meaning that if the user clicks on “True” and then clicks on “False”, it replaces the text input as you can’t have an answer both “True” and “False”.
But there is a problem with the letter buttons. If you click on the letter buttons, you realise that you can click on multiple letter buttons which is fine, but the problem is that it replaces the text input for those letters which is incorrect. If multiple letter buttons are selected, then it should display the text inputs for all of those letter buttons, not replace the text input with the latest letter button selected.
So does anyone know what I need to change in the code in order to achieve this?
You generate an
data-hidfor the button here:based on this you now generate an input field:
The id variable in this is the id of the button, which will be
answerCfor example. So with this you will get an hid of#hiddenanswerC0valuewhen you first click the button.However when you add an answer the buttons will have an id generated like this:
So it will have an extra
Rowat the end. So thedata-hidand the input box will be different as well (#hiddenanswerCRow0value).Edit:
Another problem is that you don’t actually create the data-hid for the new buttons. You only create it for the first set of buttons after clicking on them. But when you create the second set (after clicking) with the C button already activated it will not have the
data-hidset and therefore you cannot delete it.