How to: Update dialog div with new content from json
I am attempting to update the div of my dialog with new content from a json array and am encountering issues and am requesting some guidance.
I output a json array which has labels for a 'Name' and a 'Definition'. A user is presented with a list of radio buttons. When a user clicks a radio button which has the following structure:
- <input type="radio" value="23" name="statistic" id="stat-23" />
I take the value of the radio button and use this to identify which 'Name' 'Definition' pair I am referring to from my json array.
I then use the 'Name' 'Definition' pair to populate a div which typically updates dynamically. To accomplish this I use the following code:
- $('input[type=radio]').live( 'change', function(){
- if ( ! $(this).is(':checked') )
- return false;
- var stat_id = $(this).attr( 'id' ).replace( /stat-/, '' );
- refreshDefinition( stat_id );
- } );
- function refreshDefinition( stat_id ) {
- var definition = definitions[ stat_id ];
- var div = $("<div id='definition'>"+definition.name+": "+definition.definition+"</div>");
- $('#definition').replaceWith( div );
- }
This works fine without a dialog (it updates just fine as is), however, it would look a lot better if there were some way to incorporate a dialog so that when a user clicks a button, the dialog will appear and they can see the 'Name' 'Definition' pair and then can exit out of it when they are satisfied.
If you have any guidance on how I could go about solving this problem or any alternative approaches, I would really appreciate it!
Thanks.