I was trying to get all the inputs inside my form and fill the text fields with the value that came from the database. I would like to ask if there are other ways to do this because currently I am using nested switch case and it looks awful. So here is my code:
function filled(data){
modal.find('.form-control, input').each(function(index, el) {
var element = $(this).attr('name'),
$this = $(this);
switch($this.get(0).tagName){
case "INPUT" :
var $type = $this.attr('type');
switch($type){
case "radio": case "checkbox":
if($this.prop('value') == data[element])
$this.prop('checked', true);
break;
case "text": case "number":
$this.val(data[element]);
break;
}
break;
case "TEXTAREA" :
$this.text(data[element]);
break;
}
});
}