Jump to content

How to change the value of checkboxes


Maxraid

Recommended Posts

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

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.
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.