L.fcg L.fcg - 1 year ago 36
Javascript Question

How to set default values/placeholders for depended select lists?

I have four depended select lists and I want to give all the select lists a default value/placeholder like this:

select ...
. The problem is that when I try to do it like this:
<option value=""> Select ... </option>
it doesn't work. Because when I change the first select list the other select lists gets automically changed because of the dependency.

This is how I'm filling my depended select lists:

$.getJSON("dropdown_code/get_fields.php?table=" + $(this).val(), success = function(data)
optionsFields= "";
for(var i = 0; i < data.length; i++)
optionsFields += "<option value='" + data[i]['field_name'] + "'>" + data[i]['field_alias'] + "</option>";


instead of optionsFields= ""; use optionsFields= "<option value='0'> Select... </option>". it's not working because you're probably setting your default value in HTML and overwriting it in your change function.