/    Sign up×
Community /Pin to ProfileBookmark

jquery json generate html buttons with condition

Hi all,
My need is to generate buttons with conditions described in json. Help me please, I%u2019m newbie.

Here is my json 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:

<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>

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @marchello spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...