I have a modelChoiceField created with Django:
lawsToValidate=forms.ModelChoiceField(queryset=LawsIdsModel.objects.filter(validated=0).values("releveAnnee", "releveMois", "noOrdre"), widget=forms.Select(attrs={'onchange': 'javascript: lawToValidateDisplay(this.value);'}))
The django code creates this html code:
<option value="{'releveMois': 1L, 'noOrdre': 2L, 'releveAnnee': 2009L}">{'releveMois': 1L, 'noOrdre': 2L, 'releveAnnee': 2009L}</option>
The django code calls my jquery function right after the click on the drop down list. If I display the selected value in my javascript function, here is what I have:
{'releveMois': 1L, 'noOrdre': 3L, 'releveAnnee': 2009L}
How do I get the information from this python dictionnary in jquery / javascript. How do I get releveMois, releveAnnee, noOrdre? If I try jQuery.parseJSON, it does not work!
EDIT:
With the comments below, I understood that it was better to change the html output. Here is my template code to generate the drop down list:
<div id="lawsToValidateChoice" class="fieldWrapper">
{{ form.lawsToValidate.errors }}
<select onchange="javascript: lawToValidateDisplay(this.value);" name="lawsToValidate" id="id_lawsToValidate">
<option value="" selected="selected">Select a law to validate</option>
{% for law in form.lawsToValidate.field.queryset %}
<option value="{{ law.releveAnnee }},{{ law.releveMois }},{{ law.noOrdre }}">releveAnnee={{ law.releveAnnee }}, releveMois={{ law.releveMois }}, noOrdre={{ law.noOrdre }}</option>
{% endfor %}
</select>
</div>
No problem anymore to parse the values! Solved!