Skip to content

Instantly share code, notes, and snippets.

@weldan
Created October 12, 2012 12:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weldan/3879053 to your computer and use it in GitHub Desktop.
Save weldan/3879053 to your computer and use it in GitHub Desktop.
dynamic dropdown with php?
<!-- this is first dropdown, second dropdown will be based on selection from this dropdown -->
<form method="post" action="">
<select name="first_dropdown">
<option value="a">a</option>
<option value="b">b</option>
<option value="c">c</option>
</select>
<input type="submit" />
</form>
<?php
if (isset($_POST['first_dropdown']) && !empty($_POST['first_dropdown']) ):
?>
<select name="second_dropdown">
<?php
//if user select a
if ($_POST['first_dropdown'] == "a"):
?>
<option value="a1">a1</option>
<option value="a2">a2</option>
<option value="a3">a3</option>
<?php endif; ?>
<?php
//if user select b
if ($_POST['first_dropdown'] == "b"):
?>
<option value="b1">b1</option>
<option value="b2">b2</option>
<option value="b3">b3</option>
<?php endif; ?>
<?php
//if user select c
if ($_POST['first_dropdown'] == "c"):
?>
<option value="c1">c1</option>
<option value="c2">c2</option>
<option value="c3">c3</option>
<?php endif; ?>
</select>
<?php endif; ?>
@Topor68
Copy link

Topor68 commented Nov 22, 2018

wtf hahahah i like it

@thanawee321
Copy link

I want it not to be reset data in value

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment