How can I display selected cities on a different webpage after clicking a button? Currently, I can only get the results on the same page. For example, if a user selects NYC and Delhi, those cities should be displayed on another HTML page.
document.getElementById('btn').onclick = function() {
var markedCheckbox = document.getElementsByName('pl');
for (var checkbox of markedCheckbox) {
if (checkbox.checked)
document.body.append(checkbox.value + ' ');
}
}
<h2 style="color:green"> Get all marked checkboxes value </h2>
<h4> Select the City, you know </h4>
<tr>
<td> Berlin: <input type="checkbox" id="check1" name="pl" value="Berlin"> </td>
<td> NYC: <input type="checkbox" id="check2" name="pl" value="NYC"> </td>
</tr>
<tr>
<td> Delhi: <input type="checkbox" id="check3" name="pl" value="Delhi"> </td>
<td> London: <input type="checkbox" id="check4" name="pl" value="London"> </td>
</tr>
<tr>
<td> Paris: <input type="checkbox" id="check5" name="pl" value="Paris"> </td>
<td> Dhaka: <input type="checkbox" id="check6" name="pl" value="Dhaka"> </td> <br> <br>
<button id="btn">Submit</button> <br>
<h4 style="color:green" id="result"></h4>
<script type="text/javascript" src="12.js"></script>