PHP and Javascript - Storage of checkbox value chosen (in session)

0

I have some checkboxes on my page. They would be campaign choices. It follows the code of the table where they are arranged (lines of three):

<table style="font-family: Trebuchet MS; font-size: 20px" align="center">
<tr>
<td>
    <img id="imgCamp1" style="width: 280px; margin-top: 20px; margin-right: 20px" src="images/campanhas/img0001.jpg" onmouseover="this.style.cursor='pointer';" onclick=window.open(src);>
    <br><input id="chkCamp1" type="checkbox" class="cb" style="margin-left: -25px" onclick="showMe(this)"> Campanha 1
</td>
<td>
    <img id="imgCamp2" style="width: 280px; margin-top: 20px; margin-right: 20px" src="images/campanhas/img0002.jpg" onmouseover="this.style.cursor='pointer';" onclick=window.open(src);>
    <br><input id="chkCamp2" type="checkbox" class="cb" style="margin-left: -25px" onclick="showMe(this)"> Campanha 2
</td>
<td>
    <img id="imgCamp3" style="width: 280px; margin-top: 20px; margin-right: 20px" src="images/campanhas/img0003.jpg" onmouseover="this.style.cursor='pointer';" onclick=window.open(src);>
    <br><input id="chkCamp3" type="checkbox" class="cb" style="margin-left: -25px" onclick="showMe(this)"> Campanha 3
</td>
</tr>
<tr>
<td>
    <img id="imgCamp4" style="width: 280px; margin-top: 20px; margin-right: 20px" src="images/campanhas/img0004.jpg" onmouseover="this.style.cursor='pointer';" onclick=window.open(src);>
    <br><input id="chkCamp4" type="checkbox" class="cb" style="margin-left: -25px" onclick="showMe(this)"> Campanha 4
</td>
<td>
    <img id="imgCamp5" style="width: 280px; margin-top: 20px; margin-right: 20px" src="images/campanhas/img0005.png" onmouseover="this.style.cursor='pointer';" onclick=window.open(src);>
    <br><input id="chkCamp5" type="checkbox" class="cb" style="margin-left: -25px" onclick="showMe(this)"> Campanha 5
</td>
<td>
    <img id="imgCamp6" style="width: 280px; margin-top: 20px; margin-right: 20px" src="images/campanhas/img0006.png" onmouseover="this.style.cursor='pointer';" onclick=window.open(src);>
    <br><input id="chkCamp6" type="checkbox" class="cb" style="margin-left: -25px" onclick="showMe(this)"> Campanha 6
</td>
</tr>
<tr>
<td>
    <img id="imgCamp7" style="width: 280px; margin-top: 20px; margin-right: 20px" src="images/campanhas/img0007.png" onmouseover="this.style.cursor='pointer';" onclick=window.open(src);>
    <br><input id="chkCamp7" type="checkbox" class="cb" style="margin-left: -25px" onclick="showMe(this)"> Campanha 7
</td>
<td>
    <img id="imgCamp8" style="width: 280px; margin-top: 20px; margin-right: 20px" src="images/campanhas/img0003.jpg" onmouseover="this.style.cursor='pointer';" onclick=window.open(src);>
    <br><input id="chkCamp8" type="checkbox" class="cb" style="margin-left: -25px" onclick="showMe(this)"> Campanha 8
</td>
<td>
    <img id="imgCamp9" style="width: 280px; margin-top: 20px; margin-right: 20px" src="images/campanhas/img0001.jpg" onmouseover="this.style.cursor='pointer';" onclick=window.open(src);>
    <br><input id="chkCamp9" type="checkbox" class="cb" style="margin-left: -25px" onclick="showMe(this)"> Campanha 9
</td>
</tr>
</table>

The page code is already configured so that only one option can be selected. However, what I need to do is to store in a variable (probably a session) always the value of the chosen checkbox (which I believe is worth 1).

This stored value will cause a subsequent email to tell you which campaign was chosen.

How can I do this?

    
asked by anonymous 26.10.2015 / 14:39

1 answer

1
$('input[type=checkbox]').on(click,function() {
      alert($(this).attr('id'));
});

or

$('.cb').on(click,function() {
      alert($(this).attr('id'));
});

JAVASCRIPT

function showMe(element){
    alert(element.id);
}
    
26.10.2015 / 14:47