Created
October 12, 2012 12:47
-
-
Save weldan/3879053 to your computer and use it in GitHub Desktop.
dynamic dropdown with php?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 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; ?> |
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
wtf hahahah i like it