Created
January 5, 2018 10:49
-
-
Save kobeumut/45faa0171ffddf2ae9146a245a4e685b to your computer and use it in GitHub Desktop.
Delete all option except first in JQUERY
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
<select id="domain" name="domain_name" class="form-group form-control"> | |
<option id="first_domain" value="" selected disabled>Alan Adı</option> | |
<option>Deneme Değeri</option> | |
<option>Sample Value</option> | |
<option>Third Sample Value</option> | |
</select> | |
<script> | |
$('#domain').change(function () { | |
$.post("www.SITEADRESS.com/post.php", { | |
authenticity_token: "<%= form_authenticity_token.to_s %>" | |
}) | |
.done(function (response) { | |
$('#departments').find('option').not(':first').remove(); | |
response.data.data.forEach(function (element) { | |
$('#first_department').after("<option value='" + element.id + "'>" + element.name + "</option>"); | |
}); | |
}) | |
.fail(function (xhr, status, error) { | |
alert("Gönderme İşleminde sorun oluştu, lütfen sistem yöneticiniz ile görüşünüz. Hata Bilgisi: " + error); | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment