PHP and Javascript - Selected checkbox value storage (in Session)

Asked

Viewed 82 times

1

I have on my page some options in checkboxes. They would be campaign options. Follow the code of the table where they are available (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 one of Session) always the value of the checkbox chosen (which I believe is 1).

This stored value will cause a later email to say which campaign was chosen.

How can I do that?

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);
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.