CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   DOM and JSON scripting (http://www.codingforums.com/forumdisplay.php?f=15)
-   -   generate html buttons due to conditions from json (http://www.codingforums.com/showthread.php?t=282424)

marchello 11-17-2012 08:55 AM

generate html buttons due to conditions from json
 
Hi all,

My need is to generate html buttons due to conditions specified in json. Help me please, I'm newbie.

json code:
Code:

{
    "Caption": "Module caption",
    "IconsDirectory": "C://Images/",
    "Buttons": [
        {
            "Conditions": [
                {
                    "ConditionText": "1 == 1",
                    "ButtonText": "Text1",
                    "Visible": true,
                    "Colors": {
                        "FontColor": "#FFFFFF",
                        "BGColor": "#00FF00"
                    },
                    "Size": {
                        "Width": 200,
                        "Height": 50
                    },
                    "Icon": {
                        "FileName": "Smile.png",
                        "Width": 16,
                        "Height": 16
                    },
                    "Url": {
                        "UrlAddress": "http://www.google.com",
                        "OpenNewWindow": true
                    },
                    "JavaScriptAction": {
                        "Text": "alert('ok');"
                    }
                },
                {
                    "ConditionText": "2 == 2",
                    "ButtonText": "Text2",
                    "Visible": true,
                    "Colors": {
                        "FontColor": "#FFFFFF",
                        "BGColor": "#00FF00"
                    },
                    "Size": {
                        "Width": 200,
                        "Height": 50
                    },
                    "Icon": {
                        "FileName": "Smile.png",
                        "Width": 16,
                        "Height": 16
                    },
                    "Url": {
                        "UrlAddress": "http://www.google.com",
                        "OpenNewWindow": true
                    },
                    "JavaScriptAction": {
                        "Text": "alert('ok');"
                    }
                }
            ]
        }
    ]
}


html code:
Code:

<html>
<head>
<title>SMButtons</title>
<script src="jquery/jquery-1.4.2.js"></script>
<script type="text/javascript">               
//When document loaded.
$(document).ready(function(){ 
// Get data from file as JSON
            $.getJSON('weekendtask.json', function(data) {
        var buttons = data.Buttons;
          $.each(buttons, function(key, val)
          {       
                    $('<li><input type="button" onClick="'+ val.JavaScriptAction +'" value="'+ val.ButtonText +'"/></li>').appendTo('#ulObj');
          });
  });                     
          });
  </script>
</head>
<body>
<br>
<br>
<div>
<ul id='ulObj'>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
</div>
</body>
</html>



All times are GMT +1. The time now is 07:46 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.