Jump to content

Displaying certain HTML elements based on conditions?


PHPBob

Recommended Posts

Hi! Can anyone tell me how to display certain HTML elements based on what someone checks off in a check box? Is there any way to do that dynamically, or must you click Submit and get it on another page? Either way works for me, but preferably the first.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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