cementedmind / jquery-load-json

Automatically exported from code.google.com/p/jquery-load-json
0 stars 0 forks source link

Select elements are not being selected (with solution). #9

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Have a JSON file with text that matches a select element.
2. Load that JSON file in IE9.
3. The selection is not changed.

What is the expected output? A field from my JSON that matches an option value 
should select that value. What do you see instead?  Nothing is selected.

What version of the product are you using? 1.0.0 On what operating system? 
Windows Vista 64 bit using Internet Explorer 9

Please provide any additional information below.

Change the code to this:
case 'select-one':
case 'select':
    for (var i = 0; i < element.options.length; i++) {
        element.options[i].selected |= element.options[i].value == value;
    }
    break;

case 'text':

Original issue reported on code.google.com by garth.fi...@agilex.com on 18 Dec 2013 at 7:59

GoogleCodeExporter commented 8 years ago
That solution works, thanks! Should be merged to the original branch.

Original comment by bmate...@gmail.com on 16 May 2014 at 1:53

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
How to use it if value is different then the list shown.
eg.
<option value='1'>USA</option>
<option value='2'>UK</option>

Original comment by ashokpun...@gmail.com on 25 May 2014 at 5:35

GoogleCodeExporter commented 8 years ago
This solution doesn't work for me (jQuery Mobile), this do (tested).

case 'select-one':
        $(element).val(value).attr('selected', true);
        $(element).selectmenu('refresh', true);
                break;

For the select-multiple
case 'select-multiple':
           var values = value.constructor == Array ? value : [value];
           for (var j = 0; j < values.length; j++) {
            $(element).val(value[j]).attr('selected', true);
                    }
           $(element).selectmenu('refresh', true);
       break;

Original comment by fvergni...@gmail.com on 18 Jan 2015 at 8:57