Adding and getting another new textbox if select dropdown in HTML PHP -
current code snippets
html
<form action="" method="post"> <select name="particulars"> <option value="username">username</option> <option value="email">email</option> <option value="address">address</option> </select> <input type="submit" name="submit" value="get selected values" /> </form>
php
<?php if(isset($_post['submit'])){ $selected_val = $_post['particulars']; // storing selected value in variable echo $selected_val; // displaying selected value }
so example, if select username, want new text box come out can type in value inside , submit, there way can it? able echo out value, not brand new text box. sorry, english not first language, thank much! :)
i keep updating , showing i've done here.
i suggest use js.
in html
<form action="test.php" method="post"> <select name="particulars"> <option value="username">username</option> <option value="email">email</option> <option value="address">address</option> </select> <!--username textfield--> <input name="username" type="text" style="display: none"> <input type="submit" name="submit" value="get selected values" /> </form>
suggested js
//jquery <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script> <script type="text/javascript"> //to show if default option username selected $(document).ready(function(){ if($('select[name=particulars]').val() == "username"){ $('input[name=username]').show(); } }); //with changing dropdownlist, if username selected text field appear. $('select[name=particulars]').on('change', function(){ if($(this).val() == "username"){ $('input[name=username]').show(); }else { $('input[name=username]').hide().val(''); } }); </script>
in test.php
if(isset($_post['submit'])){ $selected_val = $_post['particulars']; // storing selected value in variable echo $selected_val; // displaying selected value if(isset($_post['username'])){ //added echo "user nmae: " . $_post['username']; } }
hope you.
Comments
Post a Comment