Jump to content

Updating a PHP page with radio buttons

79wjd

I have a php contact form and I would like to have options appear/disappear depending on which radio buttons are selected. I was thinking I could just put a <script> section in the flow of the PHP page to toggle a display style, but how would I get it to activate when a radio button is selected?

 

index.php page: 


<?php
    session_start();
    
    $_SESSION['startT'] = time(); 
    
    $firstName = $lastName = $email = $companyName = $pickupName = $pickupDate = $phoneNumber = $accountNumber = $comments = "";
    $qty0 = $qty1 = $qty2 = $qty3 = $qty4 = $qty5 = $qty6 = $qty7 = $qty8 = $qty9 = $qty10 = ""; 
    $item0 = $item1 = $item2 = $item3 = $item4 = $item5 = $item6 = $item7 = $item8 = $item9 = $item10 = "";
    $noErrors = true; 

    if($_POST['clearList']) {
        $_SESSION["firstname"] = $_POST["firstname"];
        $_SESSION["lastname"] = $_POST["lastname"];
        $_SESSION["email"] = $_POST["email"];
        $_SESSION["comapnyName"] = $_POST["companyName"];
        $_SESSION["accountNumber"] = $_POST["accountNumber"];
        $_SESSION["pickupName"] = $_POST["pickupName"];
        $_SESSION["phoneNumber"] = $_POST["phoneNumber"];
        $_SESSION["pickupDate"] = $_POST["pickupDate"];
    }

    if($_POST['pickupDelivery'] == "pickup"){ 
        echo '<script>
            document.getElementById("pickupName").style.display="block";
            document.getElementById("desiredPickup").style.display="block";
            document.getElementById("deliveryAddress").style.display="none";
            document.getElementById("desiredDelivery").style.display="none";
        </script>';
    } else if($_POST['pickupDelivery'] == "delivery") { 
        <script>
            document.getElementById("pickupName").style.display="none";
            document.getElementById("desiredPickup").style.display="none";
            document.getElementById("deliveryAddress").style.display="block";
            document.getElementById("desiredDelivery").style.display="block";
        </script>
    }

    if($_POST['submit']) {
        if(empty($_POST["firstname"])) {      $_SESSION["nameErr"] = "First name is required"; $noErrors=false;} 
        else {                         $firstName = $_POST['firstname']; }
        if(empty($_POST["lastname"])) {        $_SESSION["lastErr"] = "Last name is required"; $noErrors=false;}
        else {                      $lastName = $_POST['lastname']; }
        if(empty($_POST["email"])) {         $_SESSION["emailErr"] = "Email is required"; $noErrors=false;}
        else {                         $email = $_POST['email']; }
        if(empty($_POST["companyname"])) {    $_SESSION["companyErr"] = "Company name is required"; $noErrors=false;}
        else {                        $companyName= $_POST['companyname']; }
        if(empty($_POST["accountNumber"])){ $_SESSION["accountErr"] = "Account number is required"; $noErrors=false;}
        else {                        $accountNumber = $_POST['accountNumber'];}
        if(empty($_POST["number"])) {        $_SESSION["phoneErr"] = "Phone number is required"; $noErrors=false;}
        else {                        
            if(strlen($_POST['number']) >= 10) { $phoneNumber = $_POST['number']; }
            else { $_SESSION["phoneErr"] = "Invalid phone number"; $noErrors=false; }
        }

        if(!isset($_POST['pickupDelivery'])){    $_SESSION['pickupDeliveryErr'] = "Please specify pickup or delivery"; $noErrors=false;}
        else {
            if($_POST['pickupDelivery'] == "pickup"){ 
                if(empty($_POST["pickupName"])) { $_SESSION["pickupNameErr"] = "Pickup name is required"; $noErrors=false;}
                else { $pickupName = $_POST['pickupName']; }
                if(!isset($_POST['pickupDate'])){ $_SESSION['pickupDateErr'] = "Please specify a pickup date"; $noErrors=false;}
                else {
                    $today = getdate(); 
                    if($_POST['pickupDate'] == "pickupToday") {$pickupDate = $today['month'].",".$today['day'];}
                    else if($_POST['pickupDate'] == "pickupTomorrow"){$pickupDate = $today['month'].",".($today['day'] +1);}
                    else if($_POST['pickupDate'] == "pickupOther"){
                        if(empty($_POST['pickupDateOther'])) {$_SESSION["pickupDateErr"] = "Please select the desired pickup date"; $noErrors=false;}
                        else { $pickupDate = $_POST["pickupDate"]; }
                    }
                }
            } else if($_POST['pickupDelivery'] == "delivery") { 
                if(empty($_POST['streetAddress'])) {$_SESSION["streetAddressErr"] = "Please specify a street"; $noErrors=false;}
                else { $streetAddress = $_POST['streetAddress']; }
                if(empty($_POST['streetAddress'])) {$_SESSION["cityErr"] = "Please specify a city"; $noErrors=false;}
                else { $city = $_POST['city']; }
                if(empty($_POST['state'])) {$_SESSION["stateErr"] = "Please specify a state"; $noErrors=false;}
                else { $state = $_POST['state']; }
                if(empty($_POST['zip'])) {$_SESSION["zipErr"] = "Please specify a zip code"; $noErrors=false;}
                else { $state = $_POST['zip']; }

                if(!isset($_POST['deliveryDate'])){ $_SESSION['deliveryDateErr'] = "Please specify a delivery date"; $noErrors=false;}
                else {
                    $today = getdate(); 
                    if($_POST['deliveryDate'] == "deliverToday") {$deliveryDate = $today['month'].",".$today['day'];}
                    else if($_POST['pickupDate'] == "deliverTomorrow"){$deliveryDate = $today['month'].",".($today['day'] +1);}
                    else if($_POST['pickupDate'] == "deliverOther"){
                        if(empty($_POST['deliveryDateOther'])) {$_SESSION["deliveryDateErr"] = "Please select the desired delivery date"; $noErrors=false;}
                        else { $deliveryDate = $_POST["deliveryDate"]; }
                    }
                }
            }
        }


<!--ITEMS-->
        if(empty($_POST['qty0']) || empty($_POST['item0'])){ $_SESSION["item0Err"] = "At least one item is required"; $noErrors=false;}
        else {
            if(!is_numeric($_POST["qty0"])) {$_SESSION['item0Err'] = "Quantity must be a number"; $noErrors=false;}
            if(strcmp($_POST["qty0"], "0") < 1) {$_SESSION['item0Err'] = "Quantity must be greater than 0"; $noErrors=false;}
            else { $qty0 = $_POST["qty0"]; $item0=$_POST["item0"]; }
        }

        if(!empty($_POST["qty1"]) || !empty($_POST["item1"])) {
            if(empty($_POST["qty1"])) {    $_SESSION["item1Err"] = "You must specify a quantity"; $noErrors=false;}
            else if(empty($_POST["item1"])) { $_SESSION["item1Err"] = "You must specify a product"; $noErrors=false;}
            else {
                if(!isnumeric($_POST["qty1"])) {$_SESSION['item1Err'] = "Quantity must be a number"; $noErrors=false;}
                if(strcmp($_POST["qty1"], "0") < 1) {$_SESSION['item1Err'] = "Quantity must be greater than 0"; $noErrors=false;}
                else { $qty1 = $_POST["qty1"]; $item1=$_POST["item1"]; }
            }
        }
        if(!empty($_POST["qty2"]) || !empty($_POST["item2"])) {
            if(empty($_POST["qty2"])) {    $_SESSION["item2Err"] = "You must specify a quantity"; $noErrors=false;}
            else if(empty($_POST["item2"])) { $_SESSION["item2Err"] = "You must specify a product"; $noErrors=false;}
            else {
                if(!isnumeric($_POST["qty2"])) {$_SESSION['item2Err'] = "Quantity must be a number"; $noErrors=false;}
                if(strcmp($_POST["qty2"], "0") < 1) {$_SESSION['item2Err'] = "Quantity must be greater than 0"; $noErrors=false;}
                else {    $qty2 = $_POST["qty2"]; $item2=$_POST["item2"];    }
            }
        }
        if(!empty($_POST["qty3"]) || !empty($_POST["item3"])) {
            if(empty($_POST["qty3"])) {    $_SESSION["item3Err"] = "You must specify a quantity"; $noErrors=false;}
            else if(empty($_POST["item3"])) { $_SESSION["item3Err"] = "You must specify a product"; $noErrors=false;}
            else {
                if(!isnumeric($_POST["qty3"])) {$_SESSION['item3Err'] = "Quantity must be a number"; $noErrors=false;}
                if(strcmp($_POST["qty3"], "0") < 1) {$_SESSION['item3Err'] = "Quantity must be greater than 0"; $noErrors=false;}
                else { $qty3 = $_POST["qty3"]; $item3=$_POST["item3"];    }
            }
        }
        if(!empty($_POST["qty4"]) || !empty($_POST["item4"])) {
            if(empty($_POST["qty4"])) {    $_SESSION["item4Err"] = "You must specify a quantity"; $noErrors=false;}
            else if(empty($_POST["item4"])) { $_SESSION["item4Err"] = "You must specify a product"; $noErrors=false;}
            else {
                if(!isnumeric($_POST["qty4"])) {$_SESSION['item4Err'] = "Quantity must be a number"; $noErrors=false;}
                if(strcmp($_POST["qty4"], "0") < 1) {$_SESSION['item4Err'] = "Quantity must be greater than 0"; $noErrors=false;}
                else {    $qty4 = $_POST["qty4"]; $item4=$_POST["item4"]; }
            }
        }
        if(!empty($_POST["qty5"]) || !empty($_POST["item5"])) {
            if(empty($_POST["qty5"])) {    $_SESSION["item5Err"] = "You must specify a quantity"; $noErrors=false;}
            else if(empty($_POST["item5"])) { $_SESSION["item5Err"] = "You must specify a product"; $noErrors=false;}
            else {
                if(!isnumeric($_POST["qty5"])) {$_SESSION['item5Err'] = "Quantity must be a number"; $noErrors=false;}
                if(strcmp($_POST["qty5"], "0") < 1) {$_SESSION['item5Err'] = "Quantity must be greater than 0"; $noErrors=false;}
                else {    $qty5 = $_POST["qty5"]; $item5=$_POST["item5"]; }
            }
        }
        if(!empty($_POST["qty6"]) || !empty($_POST["item6"])) {
            if(empty($_POST["qty6"])) {    $_SESSION["item6Err"] = "You must specify a quantity"; $noErrors=false;}
            else if(empty($_POST["item6"])) { $_SESSION["item6Err"] = "You must specify a product"; $noErrors=false;}
            else {
                if(!isnumeric($_POST["qty6"])) {$_SESSION['item6Err'] = "Quantity must be a number"; $noErrors=false;}
                if(strcmp($_POST["qty6"], "0") < 1) {$_SESSION['item6Err'] = "Quantity must be greater than 0"; $noErrors=false;}
                else { $qty6 = $_POST["qty6"]; $item6=$_POST["item6"]; }
            }
        }
        if(!empty($_POST["qty7"]) || !empty($_POST["item7"])) {
            if(empty($_POST["qty7"])) {    $_SESSION["item7Err"] = "You must specify a quantity"; $noErrors=false;}
            else if(empty($_POST["item7"])) { $_SESSION["item7Err"] = "You must specify a product"; $noErrors=false;}
            else {
                if(!isnumeric($_POST["qty7"])) {$_SESSION['item7Err'] = "Quantity must be a number"; $noErrors=false;}
                if(strcmp($_POST["qty7"], "0") < 1) {$_SESSION['item7Err'] = "Quantity must be greater than 0"; $noErrors=false;}
                else { $qty7 = $_POST["qty7"]; $item7=$_POST["item7"]; }
            }
        }
        if(!empty($_POST["qty8"]) || !empty($_POST["item8"])) {
            if(empty($_POST["qty8"])) {    $_SESSION["item8Err"] = "You must specify a quantity"; $noErrors=false;}
            else if(empty($_POST["item8"])) { $_SESSION["item8Err"] = "You must specify a product"; $noErrors=false;}
            else {
                if(!isnumeric($_POST["qty8"])) {$_SESSION['item8Err'] = "Quantity must be a number"; $noErrors=false;}
                if(strcmp($_POST["qty8"], "0") < 1) {$_SESSION['item8Err'] = "Quantity must be greater than 0"; $noErrors=false;}
                else {    $qty8 = $_POST["qty8"]; $item8=$_POST["item8"]; }
            }
        }
        if(!empty($_POST["qty9"]) || !empty($_POST["item9"])) {
            if(empty($_POST["qty9"])) {    $_SESSION["item9Err"] = "You must specify a quantity"; $noErrors=false;}
            else if(empty($_POST["item9"])) { $_SESSION["item9Err"] = "You must specify a product"; $noErrors=false;}
            else {
                if(!isnumeric($_POST["qty9"])) {$_SESSION['item9Err'] = "Quantity must be a number"; $noErrors=false;}
                if(strcmp($_POST["qty9"], "0") < 1) {$_SESSION['item9Err'] = "Quantity must be greater than 0"; $noErrors=false;}
                else { $qty9 = $_POST["qty9"]; $item9=$_POST["item9"]; }
            }
        }
        if(!empty($_POST["qty10"]) || !empty($_POST["item10"])) {
            if(empty($_POST["qty10"])) {    $_SESSION["item10Err"] = "You must specify a quantity"; $noErrors=false;}
            else if(empty($_POST["item10"])) { $_SESSION["item10Err"] = "You must specify a product"; $noErrors=false;}
            else {
                if(!isnumeric($_POST["qty10"])) {$_SESSION['item10Err'] = "Quantity must be a number"; $noErrors=false;}
                if(strcmp($_POST["qty10"], "0") < 1) {$_SESSION['item10Err'] = "Quantity must be greater than 0"; $noErrors=false;}
                else { $qty10 = $_POST["qty10"]; $item10=$_POST["item10"]; }
            }
        }
<!--END ITEMS-->


        $comments = $_POST['comments'];

        if($noErrors == false){
            $_SESSION['firstname'] = $firstName;    
            $_SESSION['lastname'] = $lastName; 
            $_SESSION['email'] = $email; 
            $_SESSION['number'] = $phoneNumber; 
            $_SESSION['companyname'] = $companyName; 
            $_SESSION['accountNumber'] = $accountNumber;     
            $_SESSION['pickupName'] = $pickupName;    
            $_SESSION['pickupDate'] = $pickupDate; 
            $_SESSION['comments'] = $comments; 
            $_SESSION["qty0"]=$qty0; 
            $_SESSION["item0"]=$item0;
            $_SESSION["qty1"]=$qty1; 
            $_SESSION["item1"]=$item1;
            $_SESSION["qty2"]=$qty2; 
            $_SESSION["item2"]=$item2;
            $_SESSION["qty3"]=$qty3; 
            $_SESSION["item3"]=$item3;
            $_SESSION["qty4"]=$qty4; 
            $_SESSION["item4"]=$item4;
            $_SESSION["qty5"]=$qty5; 
            $_SESSION["item5"]=$item5;
            $_SESSION["qty6"]=$qty6; 
            $_SESSION["item6"]=$item6;
            $_SESSION["qty7"]=$qty7; 
            $_SESSION["item7"]=$item7;
            $_SESSION["qty8"]=$qty8; 
            $_SESSION["item8"]=$item8;
            $_SESSION["qty9"]=$qty9; 
            $_SESSION["item9"]=$item9;
            $_SESSION["qty10"]=$qty10; 
            $_SESSION["item10"]=$item10;
        }

        $header = "From: order@ihgyghjs.com";
        $to = 'dhghjn@gmail.com';
        $subject = 'Order for Pickup';

        $message = "From: \r\n 
            Name: $firstName $lastName\r\n 
            Company Name: $companyName\r\n 
            Account Number: $accountNumber\r\n
            Phone Number: $phoneNumber\r\n
            E-mail: $email\r\n 
            Pickup List: $pickupName\r\n
            Pickup Date: $pickupDate\r\n
            Items: 
            $qty0\t $item0\r\n
            $qty1\t $item1\r\n
            $qty2\t $item2\r\n
            $qty3\t $item3\r\n
            $qty4\t $item4\r\n
            $qty5\t $item5\r\n
            $qty6\t $item6\r\n
            $qty7\t $item7\r\n
            $qty8\t $item8\r\n
            $qty9\t $item9\r\n
            $qty10\t $item10\r\n\r\n
            Additional Requests: $comments";
        
        if(($noErrors == true) && mail ($to, $subject, $message, $header)) {
            unset($_SESSION['firstname']);
            unset($_SESSION['lastname']);
            unset($_SESSION['email']);
            unset($_SESSION['companyname']);
            unset($_SESSION['accountNumber']);
            unset($_SESSION['number']);
            unset($_SESSION['comments']);
            unset($_SESSION['pickupName']);
            unset($_SESSION['pickupDate']);
            unset($_SESSION['qty0']); 
            unset($_SESSION['qty1']);
            unset($_SESSION['qty2']);
            unset($_SESSION['qty3']);
            unset($_SESSION['qty4']);
            unset($_SESSION['qty5']);
            unset($_SESSION['qty6']);
            unset($_SESSION['qty7']);
            unset($_SESSION['qty8']);
            unset($_SESSION['qty9']);
            unset($_SESSION['qty10']);
            unset($_SESSION['item0']);
            unset($_SESSION['item1']);
            unset($_SESSION['item2']);
            unset($_SESSION['item3']);
            unset($_SESSION['item4']);
            unset($_SESSION['item5']);
            unset($_SESSION['item6']);
            unset($_SESSION['item7']);
            unset($_SESSION['item8']);
            unset($_SESSION['item9']);
            unset($_SESSION['item10']);
            $_SESSION['status'] = "Your message has been sent!";
            header('Location: demo.php');
        } else {
            $_SESSION['status'] = "Something went wrong, please try again";
            header('Location: demo.php');
        }
        exit();
    }
?>

PSU Tier List | CoC

Gaming Build | FreeNAS Server

Spoiler

i5-4690k || Seidon 240m || GTX780 ACX || MSI Z97s SLI Plus || 8GB 2400mhz || 250GB 840 Evo || 1TB WD Blue || H440 (Black/Blue) || Windows 10 Pro || Dell P2414H & BenQ XL2411Z || Ducky Shine Mini || Logitech G502 Proteus Core

Spoiler

FreeNAS 9.3 - Stable || Xeon E3 1230v2 || Supermicro X9SCM-F || 32GB Crucial ECC DDR3 || 3x4TB WD Red (JBOD) || SYBA SI-PEX40064 sata controller || Corsair CX500m || NZXT Source 210.

Link to comment
Share on other sites

Link to post
Share on other sites

6 minutes ago, mikat said:

use css to let elements appear and disappear with display:none?

I tried that in the same place that I tried to use JS but it didn't work either. 

PSU Tier List | CoC

Gaming Build | FreeNAS Server

Spoiler

i5-4690k || Seidon 240m || GTX780 ACX || MSI Z97s SLI Plus || 8GB 2400mhz || 250GB 840 Evo || 1TB WD Blue || H440 (Black/Blue) || Windows 10 Pro || Dell P2414H & BenQ XL2411Z || Ducky Shine Mini || Logitech G502 Proteus Core

Spoiler

FreeNAS 9.3 - Stable || Xeon E3 1230v2 || Supermicro X9SCM-F || 32GB Crucial ECC DDR3 || 3x4TB WD Red (JBOD) || SYBA SI-PEX40064 sata controller || Corsair CX500m || NZXT Source 210.

Link to comment
Share on other sites

Link to post
Share on other sites

Did you try having chrome console open to see if there are any errors? also there is no form on that page so the script isn't going to be changing anything.

 

 

 

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
Share on other sites

Link to post
Share on other sites

3 minutes ago, vorticalbox said:

Did you try having chorme console open to see if there are any errors? ctrl + shift + i the else if doesn't echo the script to the page.

 


if($_POST['pickupDelivery'] == "pickup"){ 
        echo '<script>
            document.getElementById("pickupName").style.display="block";
            document.getElementById("desiredPickup").style.display="block";
            document.getElementById("deliveryAddress").style.display="none";
            document.getElementById("desiredDelivery").style.display="none";
        </script>';
    } else if($_POST['pickupDelivery'] == "delivery") { 
        echo '<script>
            document.getElementById("pickupName").style.display="none";
            document.getElementById("desiredPickup").style.display="none";
            document.getElementById("deliveryAddress").style.display="block";
            document.getElementById("desiredDelivery").style.display="block";
        </script>';
    }

 

 

I solved it by doing this: https://jsfiddle.net/8rjn9v68/11/

Although, I'm not not sure how I would get it to save the display states of the divs through a page refresh. I'm using a Session to maintain the value/status of the radio button, but when I refresh the page the radio button remains checked but all the divs end up being hidden since the main.css files is hiding them all by default. 

PSU Tier List | CoC

Gaming Build | FreeNAS Server

Spoiler

i5-4690k || Seidon 240m || GTX780 ACX || MSI Z97s SLI Plus || 8GB 2400mhz || 250GB 840 Evo || 1TB WD Blue || H440 (Black/Blue) || Windows 10 Pro || Dell P2414H & BenQ XL2411Z || Ducky Shine Mini || Logitech G502 Proteus Core

Spoiler

FreeNAS 9.3 - Stable || Xeon E3 1230v2 || Supermicro X9SCM-F || 32GB Crucial ECC DDR3 || 3x4TB WD Red (JBOD) || SYBA SI-PEX40064 sata controller || Corsair CX500m || NZXT Source 210.

Link to comment
Share on other sites

Link to post
Share on other sites

2 minutes ago, djdwosk97 said:

I solved it by doing this: https://jsfiddle.net/8rjn9v68/11/

Although, I'm not not sure how I would get it to save the display states of the divs through a page refresh. I'm using a Session to store the value of the radio button, but when I refresh the page the radio button remains checked but all the divs end up being hidden. 

use JS to check which button is pressed and hide accordingly should do it. 

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
Share on other sites

Link to post
Share on other sites

24 minutes ago, vorticalbox said:

use JS to check which button is pressed and hide accordingly should do it. 

Like this?

 

function checkCheckedStatus() {

    if(document.getElementById("pickup").checked){

          document.getElementById("box1").style.display="none";
          document.getElementById("box2").style.display="block";

    } else if (document.getElementById("delivery").checked){

        document.getElementById("box1").style.display="block";
          document.getElementById("box2").style.display="none";

    }

}

Edit: I had a typo. It works. 

PSU Tier List | CoC

Gaming Build | FreeNAS Server

Spoiler

i5-4690k || Seidon 240m || GTX780 ACX || MSI Z97s SLI Plus || 8GB 2400mhz || 250GB 840 Evo || 1TB WD Blue || H440 (Black/Blue) || Windows 10 Pro || Dell P2414H & BenQ XL2411Z || Ducky Shine Mini || Logitech G502 Proteus Core

Spoiler

FreeNAS 9.3 - Stable || Xeon E3 1230v2 || Supermicro X9SCM-F || 32GB Crucial ECC DDR3 || 3x4TB WD Red (JBOD) || SYBA SI-PEX40064 sata controller || Corsair CX500m || NZXT Source 210.

Link to comment
Share on other sites

Link to post
Share on other sites

You should learn to use arrays.  Instead of 10 ifs for each item, you could do a for i from 1 to 10 and be done with it.

Also, you can use an array for the error messages so you could simply say $ErrorList[] = 'something'; to add one error message to the list of errors or warnings. This way you can also display multiple errors, not just the last one detected.  Oh, and it's not common practice to use double negatives ... i mean you use $noErrors=false;  when you could instead use something like $errorFound = true;  ... the default state is false, no errors, so it seems kind of logical to flip a variable to true / yes when at least one error was detected, not the other way around " no errors flag is no longer true"    

Group the radio buttons you want to show or hide in a div, give that div an id or name... use the selectbyid javascript thing to select the div and put the css property display:none; on it to hide, or display:block; or something else to make it visible.

 

Link to comment
Share on other sites

Link to post
Share on other sites

5 hours ago, djdwosk97 said:

I solved it by doing this: https://jsfiddle.net/8rjn9v68/11/

Although, I'm not not sure how I would get it to save the display states of the divs through a page refresh. I'm using a Session to maintain the value/status of the radio button, but when I refresh the page the radio button remains checked but all the divs end up being hidden since the main.css files is hiding them all by default. 

You'll probably want to make a function that takes an argument, then hide all of the items except the one passed in by the argument.

Link to comment
Share on other sites

Link to post
Share on other sites

3 minutes ago, prolemur said:

You'll probably want to make a function that takes an argument, then hide all of the items except the one passed in by the argument.

I did something similar: 

5 hours ago, djdwosk97 said:

I solved it by doing this: https://jsfiddle.net/8rjn9v68/11/

 

5 hours ago, mariushm said:

You should learn to use arrays.  Instead of 10 ifs for each item, you could do a for i from 1 to 10 and be done with it.

 

Also, you can use an array for the error messages so you could simply say $ErrorList[] = 'something'; to add one error message to the list of errors or warnings. This way you can also display multiple errors, not just the last one detected.  Oh, and it's not common practice to use double negatives ... i mean you use $noErrors=false;  when you could instead use something like $errorFound = true;  ... the default state is false, no errors, so it seems kind of logical to flip a variable to true / yes when at least one error was detected, not the other way around " no errors flag is no longer true"    

Group the radio buttons you want to show or hide in a div, give that div an id or name... use the selectbyid javascript thing to select the div and put the css property display:none; on it to hide, or display:block; or something else to make it visible.

 

All the errors are display at the same time anyway, and I will replace the multiple items with a for loop.

 

As for the double negative, to each their own. I get style and all, but whatever, I'll be the one maintaining this site anyway. 

 

And that's exactly what I had in my original post but there was a slight bug that I missed. 

PSU Tier List | CoC

Gaming Build | FreeNAS Server

Spoiler

i5-4690k || Seidon 240m || GTX780 ACX || MSI Z97s SLI Plus || 8GB 2400mhz || 250GB 840 Evo || 1TB WD Blue || H440 (Black/Blue) || Windows 10 Pro || Dell P2414H & BenQ XL2411Z || Ducky Shine Mini || Logitech G502 Proteus Core

Spoiler

FreeNAS 9.3 - Stable || Xeon E3 1230v2 || Supermicro X9SCM-F || 32GB Crucial ECC DDR3 || 3x4TB WD Red (JBOD) || SYBA SI-PEX40064 sata controller || Corsair CX500m || NZXT Source 210.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×