Pavlos1316 Posted May 29, 2008 Share Posted May 29, 2008 ...for me at least! Hi there. What I have: 1. I have - ready and working - my connection string to post in mysql db. - TESTED - Ok! What I want: 1. Let's say my form is like: b1 b2 b3 b4b5b6 b7b8b9 1.a. Columns are used as check boxes. 2. The problem: 2.a. User MUST check 4 columns only - one in each row + a 2nd one in one of the rows. 2.b. When they check the 4th one, other columns must not be able to be checked. 2.c. User must not be able to check 4 columns in only 2 rows. This may be the last step for my site but I have no idea how to do it!!! ??? I hope you can help. Thanks. Quote Link to comment Share on other sites More sharing options...
phpzone Posted May 29, 2008 Share Posted May 29, 2008 Your asking someone to write a complete application for you basically and I doubt anyone has time. I would probably start by making the rows form arrays and then you can check if more than one value is in each row. eg. row1 = <input type="checkbox" name="a[1]" value="1" /> <input type="checkbox" name="a[2]" value="2" /> <input type="checkbox" name="a[3]" value="3" /> To check if more than one is selected in that row: $a = $_POST["a"]; echo count( $a ); If the user checked 1 and 2 your count would be 2 So you know you can't have two on the next two arrays. Time to get the thinking cap on Sorry, I don't have time to write the whole thing. Quote Link to comment Share on other sites More sharing options...
craygo Posted May 29, 2008 Share Posted May 29, 2008 What you are actually asking has to do with javascript. PHP won't be able to help unless the form is submitted. Ray Quote Link to comment Share on other sites More sharing options...
DarkWater Posted May 29, 2008 Share Posted May 29, 2008 You're asking for Javascript help. PHP only handles the backend, while Javascript handles dynamic frontends. Also, we will not write the entire application for you. If you want that, go to the Freelance board and be prepared to pay someone. Quote Link to comment Share on other sites More sharing options...
phpzone Posted May 29, 2008 Share Posted May 29, 2008 Yes, it might be best to check in javascript first, however, what about people without javascript enabled? Like me, who run NoScript in Firefox. (Just to be awkward) Using a combination of checking _POST and storing in _SESSION is would be possible to do what they want. I would check the POST, if its valid store in in the SESSION, reverting to the SESSION version if the last POST contained an invalid selection. It's probably simpler in Javascript, and my first notion was to respond saying use javascript, but is probably best to use both or just stick with a PHP version. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted May 29, 2008 Share Posted May 29, 2008 Then don't let them use the form and redirect them to something else. They can turn NoScript off if they really want to use your site. Quote Link to comment Share on other sites More sharing options...
phpzone Posted May 29, 2008 Share Posted May 29, 2008 I don't actually know what they are trying to achieve, so perhaps yes I was just answering in the context of it being a PHP question. Anyway, good luck to the poster, whether you decide on PHP or JS. Quote Link to comment Share on other sites More sharing options...
Pavlos1316 Posted May 29, 2008 Author Share Posted May 29, 2008 I think I will stick in php. There is nothing you can't do if you now the right words and philosophy. but for this script I don't even know what to serch for... e.g. for login form you search login.php. For this one??? Quote Link to comment Share on other sites More sharing options...
Psycho Posted May 29, 2008 Share Posted May 29, 2008 Here is a javascript solution. Of course you SHOULD create the same functionality in PHP in case users have JS disabled - the same logic will apply. But, for situations like these I think the addition of Javascript is a definite benefit: I'm sure this could be done more efficiently, but based upon the time I was willing to invest in this it does work. <html> <head> <script type="text/javascript"> function validateCheck() { formObj = document.getElementById('grid'); var totalCount = 0; var rowCount = new Array(); rowCount[0] = 0; rowCount[1] = 0; rowCount[2] = 0; for (var i=1; i<=9; i++) { if (formObj['B'+i].checked) { totalCount++; rowCount[(Math.ceil(i/3)-1)]++; } } var disableState = new Array(); disableState[0] = false; disableState[1] = false; disableState[2] = false; //Determine rows to disable if (totalCount==4) { disableState[0] = true; disableState[1] = true; disableState[2] = true; } else { if (rowCount[0]==2 || (rowCount[0]==1 && (rowCount[1]==2 || rowCount[2]==2))) { disableState[0] = true; } if (rowCount[1]==2 || (rowCount[1]==1 && (rowCount[0]==2 || rowCount[2]==2))) { disableState[1] = true; } if (rowCount[2]==2 || (rowCount[2]==1 && (rowCount[0]==2 || rowCount[1]==2))) { disableState[2] = true; } } //Disable/enable unchecked boxes for (var i=1; i<=9; i++) { if (!formObj['B'+i].checked) { formObj['B'+i].disabled = disableState[(Math.ceil(i/3)-1)]; } } return; } </script> </head> <body> <form name="grid" id="grid"> <table border="1"> <tr> <td><input type="checkbox" id="B1" name="B1" value="B1" onclick="validateCheck();" />B1</td> <td><input type="checkbox" id="B2" name="B2" value="B2" onclick="validateCheck();" />B2</td> <td><input type="checkbox" id="B3" name="B3" value="B3" onclick="validateCheck();" />B3</td> </tr> <tr> <td><input type="checkbox" id="B4" name="B4" value="B4" onclick="validateCheck();" />B4</td> <td><input type="checkbox" id="B5" name="B5" value="B5" onclick="validateCheck();" />B5</td> <td><input type="checkbox" id="B6" name="B6" value="B6" onclick="validateCheck();" />B6</td> </tr> <tr> <td><input type="checkbox" id="B7" name="B7" value="B7" onclick="validateCheck();" />B7</td> <td><input type="checkbox" id="B8" name="B8" value="B8" onclick="validateCheck();" />B8</td> <td><input type="checkbox" id="B9" name="B9" value="B9" onclick="validateCheck();" />B9</td> </tr> </table> </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
Pavlos1316 Posted May 29, 2008 Author Share Posted May 29, 2008 I will test it but not right away. And Thanks for every second of your time!!! 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.