html - Get selected text from dropdown in PHP -
i totally new in php, in fact reason doing customize wordpress plugin can fit need. far have default form, doing add country dropdown. here's how add it
<div class="control-group"> <label class="control-label" for="country">country :</label> <div class="controls"> <select id="itemtype_id" name="cscf[country]" class="input-xlarge"> <option value="malaysia@email.com">malaysia</option> <option value="indonesia@email.com">indonesia</option> </select> <span class="help-inline"></span> </div> </div>
so far able retrieve value of selected item
$cscf['country'];
how can display text country name in case ?
you can use hidden field, , javascript , jquery can set value field, when selected value of dropdown changes.
<select id="itemtype_id" name="cscf[country]" class="input-xlarge"> <option value="malaysia@email.com">malaysia</option> <option value="indonesia@email.com">indonesia</option> </select> <input type="hidden" name="country" id="country_hidden"> <script> $(document).ready(function() { $("#itemtype_id").change(function(){ $("#country_hidden").val(("#itemtype_id").find(":selected").text()); }); }); </script>
then when page submitted, can name of country using
$_post["country"]
Comments
Post a Comment