Skip to content

Instantly share code, notes, and snippets.

@kobeumut
Created January 5, 2018 10:49
Show Gist options
  • Save kobeumut/45faa0171ffddf2ae9146a245a4e685b to your computer and use it in GitHub Desktop.
Save kobeumut/45faa0171ffddf2ae9146a245a4e685b to your computer and use it in GitHub Desktop.
Delete all option except first in JQUERY
<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