Maxraid Posted November 28, 2006 Share Posted November 28, 2006 What is wrong here?, this question has probably been here a thousand times before, but i doesn't seem to find the answer here.Anyway I have a website with alot of checkboxes, so I made an array, which im running trough to see if they are checked and if they are i change the value to "YES".$checkboxArray = array("$testa","$testb","$testc"); for($counter=1; $counter<3; $counter++) { if ($checkboxArray[$counter] == on) { $checkboxArray[$counter] = "YES"; } else { $checkboxArray[$counter] = "NO"; } }It doesn't work and mayby I'm handling the problem in a wrong way, mayby there is a better way.Can anybody help me Link to comment https://forums.phpfreaks.com/topic/28713-how-to-change-the-value-of-checkboxes/ Share on other sites More sharing options...
gin Posted November 28, 2006 Share Posted November 28, 2006 What do you need the YES for? You should be doing something like this:[code]<?php$max = sizeof($checkboxArray);for($counter=0; $counter<$max; $counter++) { if ($checkboxArray[$counter] == true) echo '<input type="checkbox" checked>'; else echo '<input type="checkbox">';}?>[/code]Remember that array indexes start at 0. Link to comment https://forums.phpfreaks.com/topic/28713-how-to-change-the-value-of-checkboxes/#findComment-131483 Share on other sites More sharing options...
Maxraid Posted November 28, 2006 Author Share Posted November 28, 2006 Sorry my explaination probably a bit short, I need the "YES" because I want to display YES or NO on the page that will be showed after the user click the send button on the form, I send the variables to the next page and atfer that i wiil send them in a email. the variables testA, testB an so on, contans either on or nothing when i post them.[code] if ($testa == "on") { $testa = "YES"; } else { $testa = "NO"; } echo("$testa");[/code]If i make the code like this its working fine, but i have 25 checkboxes and therefore i thought i wolud be better to put them in an array. Link to comment https://forums.phpfreaks.com/topic/28713-how-to-change-the-value-of-checkboxes/#findComment-131508 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.