473,498 Members | 1,648 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

On-Screen Alert checkbox

4 New Member
I have a PHP page with some checkboxes.

I need to do that: When I click on a button, an alert comes out to show me all the IDs of the selected boxes. How can I do this?

Visual example:

| BUTTON| - View the selected tests in an alert.

⬜ ALL | PRODUCT | SAMPLE ID

⬜ - - - Test 1 - - SD7168

⬜ - - - Test 2 - - BH1560

⬜ - - - Test 3 - - CP4327


So I want if, for example, I selected test 1, an alert comes to me informing me the ID (SD7168) of the test I selected.

Expand|Select|Wrap|Line Numbers
  1. // Button 
  2. <h4>
  3.    <a href="" class="btn btn-info" onclick="return confirm('View selected tests')">
  4.      <br><small>TEST ID</small></a>
  5. </h4>
  6.  
  7. // Checkbox select all
  8. <tr>
  9.     <th><input type="checkbox" name="select-all" id="select-all"/>
  10.          <label for="select-all" class='smallLabel'></label>
  11.     </th>
  12. </tr>
  13.  
  14. // Checkbox select single
  15.  
  16. <tr>
  17.     <td>
  18.        <input type="checkbox" name="<?='checkbox-'.$num?>" id="<?='checkbox-'.$num?>"/>
  19.           <label for="<?='checkbox-'.$num?>" class='smallLabel'></label>
  20.     </td>
  21.  
  22. // ID parameter
  23.  
  24.     <td>
  25.        <?=$test->sampleID?> Select: <input id="<?='checkbox-'.$num?>" type="checkbox"/> <br>
  26.     </td>
  27.  
  28. // JS Checkboxes
  29.  
  30. <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  31.  
  32. // Listen for click on toggle checkbox
  33.     $('#select-all').click(function(event) {   
  34.         if(this.checked) {
  35.             // Iterate each checkbox
  36.             $(':checkbox').each(function() {
  37.                 this.checked = true;                        
  38.             });
  39.         } else {
  40.             $(':checkbox').each(function() {
  41.                 this.checked = false;                       
  42.             });
  43.         }
  44.     }); 
  45.  
  46.  
  47. // JS che I created to manage the alert
  48.  
  49. $('<?='checkbox-'.$num?>').click(function() {
  50.     alert("Checkbox state (method 1) = " + $('<?='checkbox-'.$num?>').prop('checked'));
  51.     alert("Checkbox state (method 2) = " + $('<?='checkbox-'.$num?>').is(':checked'));
  52. });
  53. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
  54.  
Dec 6 '21 #1
2 24979
dev7060
639 Recognized Expert Contributor
What is not working in the posted code?

I need to do that: When I click on a button, an alert comes out to show me all the IDs of the selected boxes. How can I do this?
Add an event listener or onclick event with the button. In the function (called by the event handler), extract the IDs of the selected checkboxes using DOM then show them using alert().
Dec 15 '21 #2
RamananKalirajan
608 Contributor
Seeing your code I see you have used JQuery. You can get all the Inputs of type checkbox in an array and iterate it, see whether the checked attribute is true or false. For checked inputs, you can collect the ID's and show it in an alert window.
Apr 25 '22 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
7274
by: Steph | last post by:
Hello, Can someone tell me the script to use for having a change on the same page when using checkbox function ? For example, i would to check one condition and display dynamically a button...
6
1702
by: NnlGggTuqPvt | last post by:
I have a form with a checkbox. Using MSIE, the user marks the checkbox, submits the form and gets his result. Then he uses the browsers back button to return to the form. Here I have a...
5
3656
by: DotNetJunkies User | last post by:
1. i want to populate checkboxlist using javascript only at client side ....how can i do this..by populate word i mean that checkboxes should be checked or unchecked on some condition basis.......
7
2216
by: Ron | last post by:
I have an HTML page, that calls an ASP javascript page on "Submit". Everything works correctly except that I can't get the value of the checkboxes. I've been trying code like this: var s = "Off"...
1
19110
by: Scott | last post by:
I'm trying to validate a checkbox below on Sumbit. If the checkbox named "myForm.myCheckBox" isn't checked, then the code in CODE 1 displays False, which is correct. However, when I test that...
0
4076
by: cyberdawg999 | last post by:
Greetings all in ASP land I have overcome one obstacle that took me 2 weeks to overcome and I did it!!!!! I am so elated!! thank you to all who invested their time and energy towards helping me...
3
3664
by: uremog | last post by:
I have a set of of check boxes. onClick, the checkboxes call check_radio and recup_checkbox. the referenced radios function as group selectors. check_radio just unchecks the radios if someone...
0
3088
by: TechnoAtif | last post by:
<?php include "dbconnect.php"; include "commonFunc.php"; ?> <!----------------------------------> <table width="80%" border="1" cellpadding="2" cellspacing="0"> <tr > <td...
3
1937
by: chiku1523 | last post by:
Hi, Please find the following code. In function setAnswers, I am looping with each question. I have inner loop, which is looping for each answers of the questions. If any of the answer for question...
4
2033
Ajay Bhalala
by: Ajay Bhalala | last post by:
Hi, I have a registration form. I want to validate this form in php using javascript. Here is my code of registration form : <html> <head>
0
7005
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6891
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7381
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5465
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4916
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4595
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3096
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3087
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
293
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.