javascript - Loop through all the elements of select and add a blank option if the either of the items is null -
i have 2 drop downs select1 , select2. select item1 of select1 , click ok button ( case in need help)
then if selectedindex 0 ( ie first option )then loop through items of both drop downs.
if same index elements ( eg 3rd element of both drop downs)are not null execute code , if either of them null execute other code, how can achieve this?
<select name="select1" id="select1" multiple size="10"> <option>1<option> <option>null<option> <option>null<option> <option>2<option> <option>3<option> </select> <select name="select2" id="select2" multiple size="10"> <option>4<option> <option>5<option> <option>6<option> <option>null<option> <option>10<option> </select>
i tried code fiddle become unresponsive.
as can see in comments. not breaking loop after adding null when first match found.
http://jsfiddle.net/678hmujh/19/ works ok me.
if (options1[i].text != "null" && options2[i].text != "null") { $(sel1).append("<option value=''>null</option>"); $(sel2).prepend("<option value=''>null</option>"); return; }
Comments
Post a Comment