I have a string that looks like this:
<input type='checkbox' name='list' class='indent-28' value = 'ABC' name='Netherlands'>
<label>Netherlands</label><br>
<input type='checkbox' name='list' class='indent-28' value = 'DEF' name='Germany'>
<label>Germany</label><br>
<input type='checkbox' name='list' class='indent-28' value = 'GHI' name='Italy'>
<label>Italy</label><br>
<input type='checkbox' name='list' class='indent-44' value = 'JKL' name='Brazil'>
<label>Brazil</label><br>
<input type='checkbox' name='list' class='indent-44' value = 'MNO' name='Argentina'>
<label>Argentina</label><br>
<input type='checkbox' name='list' class='indent-44' value = 'PQR' name='Argentina'>
<label>Argentina</label><br>
I also have two JavaScript arrays which are dynamically generated in accordance with the checkboxes the end user selects and with the respective values he/she wants to enter for these selected items.
So, assuming the user selects "Netherlands","Germany","Argentina"
and "Argentina"
from the above list, the first array will be ["Netherlands","Germany","Argentina","Argentina"]
.
Furthermore, if the user wishes to modify the values of these attributes, he/she can do so by entering new values in text boxes that I've provided in the application.
(In this case let's say X,Y,Z,W
are the new values the user wishes to enter. Hence, the second array will be ["X","Y","Z","W"]
)
Now, I have both the arrays with me and I just want to replace the values of the attributes in the above string with those in the modified array.
The desired output/end result would be something like this:
<input type='checkbox' name='list' class='indent-28' value = 'X' name='Netherlands'>
<label>Netherlands</label><br>
<input type='checkbox' name='list' class='indent-28' value = 'Y' name='Germany'>
<label>Germany</label><br>
<input type='checkbox' name='list' class='indent-28' value = 'GHI' name='Italy'>
<label>Italy</label><br>
<input type='checkbox' name='list' class='indent-44' value = 'JKL' name='Brazil'>
<label>Brazil</label><br>
<input type='checkbox' name='list' class='indent-44' value = 'Z' name='Argentina'>
<label>Argentina</label><br>
<input type='checkbox' name='list' class='indent-44' value = 'W' name='Argentina'>
<label>Argentina</label><br>
X,Y,Z
and W
should ideally replace the previous values ABC,DEF,MNO
and PQR
respectively in the string.
Can anybody help me with this code?
name
attribute twice for each checkbox in your original string? Why is Argentina in the list twice? Where does the original string come from? It might be easier to construct the string from scratch than to do some non-trivial searching and replacing. – M Oehm May 6 '14 at 8:04