Jump to content

Displaying certain HTML elements based on conditions?


PHPBob

Recommended Posts

if you want to alter page options dinamically according to what the user selects, without refreshing the page, you need javascript (theres another forum that can certainly help you with that)

 

you basically capture the users selections with onchange="" and call javascript functions that can in place add forms, images, etc to divs on your page.

To do it dynamically you'd need to use javascript.

 

If you want to do it with PHP you can do something like this:

 

the form:

<form method="post" action="nextPage.php">
<input type="checkbox" name="optionA"> Option A
<input type="checkbox" name="optionB"> Option B
<input type="checkbox" name="optionC"> Option C
</form>

 

the receiving page:

<?php

$optionA = $_REQUEST['optionA'];
$optionB = $_REQUEST['optionB'];
$optionC = $_REQUEST['optionC'];

if($optionA == "on") { ?>

your HTML elements for Option A here

<?php } elseif($optionB == "on") { ?>

option B

<?php } elseif($optionC == "on") { ?>

option C

<?php } else { ?>

if none are selected

<?php } ?>

 

The above will change if you need to factor in multiple selections, etc. but that's the basics of it

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.