php - Multiple select option selected will be view in another html element using javascript or jquery -
i have multiple select option on html :
<div class="control-group"> <label class="control-label" for="selecterror1">ditujukan untuk :</label> <div class="controls"> <select id="email" multiple data-rel="chosen" class="input-xlarge" name="email[]"> <?php foreach ($atasan $data) { echo "<option value='" . $data['email'] . "'>" . $data['email'] . "</option>"; } ?> </select> </div> </div>
my goal is, when user selected or option, option selected view in html element <p id='emailsend'>this email : email1, email2... on</p
.
i newbie in jquery. guess 'on change' or change can this.
this jquery's code:
$(document).ready(function() { $('#emailsend').hide(); $('email').change(function(){ //any idea ??? }); }
edit wondering increase ability, how should if want append on input text like
<input type="text" id="emailsend" name="emailsend">
so, jquery looked :
$("#email").change(function() { var elements = $("#email option:selected").length; $(".emailsend").html(""); $.each($("#email option:selected"), function(index, element) { $(".emailsend").val($(this).html()); if (index < elements - 1) { $(".emailsend").append(", "); } }); });
what can :
$("#email").change(function() { var elements = $("#email option:selected").length; $("#emailsend").html(""); $.each($("#email option:selected"), function(index, element){ $("#emailsend").append($(this).html()); if (index < elements-1) { $("#emailsend").append(", "); } }); });
with emailsend
being block containing emails. note solution allows handle multiple values.
edit : grammar :(
Comments
Post a Comment