I have this script which has some logic and html dropdown is selected from that,i need to send data to a API through ajax so i need to store data from the dropdown selected.
$('#state1').html('<option value="">Select state</option>');
$('#city1').html('<option value="">Select city</option>');
}
});
$(document).on('change', '#state1', function() {
var state_id = $(this).val();
if (state_id != '') {
load_json_data('city1', state_id);
} else {
$('#city1').html('<option value="">Select city</option>');
}
});
//console.log($get = $("#country1 option[value='"+$value.name+"']").text());
//var selectValue = document.getElementById('list').value; var selectOption = $("#list option[value=" + selectValue + "]").text();
//console.log($("#country1 option:selected").text());
//console.log($(this).find("option:selected").text());
$.ajax({
crossDomain: true,
url: 'xyz',
cache: false,
type: 'POST',
data: clientDetail,
success: function(data) {
self.SuccessMessage1(JSON.stringify(data))
}
}).fail(
function(xhr, textStatus, err) {
(alert("Error happened " + Object.keys(err).join(' ')))
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<html>
</p>
COUNTRY:
<select name="country" id="country" class="form-control input-lg">
<option value="">Select country</option>
</select>
</p>
<p>
STATE:
<select name="state" id="state" class="form-control input-lg">
<option value="">Select state</option>
</select>
</p>
<p>
CITY:
<select name="city" id="city" class="form-control input-lg">
<option value="$data.city">Select city</option>
</select>
</p>
</html>
i just need to send country,state and city to the api.