solarisuser Posted October 3, 2007 Share Posted October 3, 2007 Hi All, I have a page that has 20 checkboxes, sometimes with multiple pages (pagination). The "id" for each checkbox is checkbox_XXXX where XXXX is the mysql id. It's similar to a shopping cart, where the user can select one or more checkboxes, and click "Add to Shopping Cart". I'd like to have a JS that verifies at least one checkbox has been selected before running the $_POST code to add to shopping cart, and if not, just throw an alert with a message. Thanks Quote Link to comment Share on other sites More sharing options...
emehrkay Posted October 3, 2007 Share Posted October 3, 2007 var input = document.getElementById('container').getElementsByTagName('input'); var checkboxes = []; for(x in input){ if(input[x].type == 'checkbox') checkboxes.push(input[x]); } //now you have an array of all of the checkboxes inside of container. loop through that array to do some stuff Quote Link to comment Share on other sites More sharing options...
solarisuser Posted October 4, 2007 Author Share Posted October 4, 2007 Hey There, Can you please post your code in [ code] (minus space) so I can see it all =) Quote Link to comment Share on other sites More sharing options...
RichardRotterdam Posted October 4, 2007 Share Posted October 4, 2007 just a suggestion why not render the id's ascending its the value that should matter for you input not the id another way is just to loop through all input elements in your form Quote Link to comment Share on other sites More sharing options...
emehrkay Posted October 4, 2007 Share Posted October 4, 2007 sorry about that var input = document.getElementById('container').getElementsByTagName('input'); var checkboxes = []; for(x in input){ if(input[x].type == 'checkbox') checkboxes.push(input[x]); } //now you have an array of all of the checkboxes inside of container. loop through that array to do some stuff Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.