I want to integrate my javascript file in my asp.net mvc app but when adding my .js file in the scripts folder and then placing the following line in my view, there is an error. I think that is because I do not have to place it in the but in the , but not in _layout.cshtml because it does not appear in all pages.
<script src="@Url.Content("~/Scripts/test.js")" type="text/javascript"></script>
Here is my script:
cars = new Array("Mercedes", "Volvo", "BMW", "porche");
phones = new Array('Samsung', 'Nokia', 'Iphone');
names = new Array('Kasper', 'Elke', 'Fred', 'Bobby', 'Frits');
colors = new Array('blue', 'green', 'yellow');
populateSelect();
$(function () {
$('#cat').change(function () {
populateSelect();
});
});
function populateSelect() {
cat = $('#cat').val();
$('#item').html('');
eval(cat).forEach(function (t) {
$('#item').append('<option>' + t + '</option>');
});
}
So first can you tell me what is wrong with my .js file and is it relevant to use javascipt or do I have to use Ajax( I hope no) ?
The script is for populating a dropdownlist based on the choice of the previous one, then can you help me how to do if I want to populate theses dropdownlist using data in SQL server ?
Thank you for your help