Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8847477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:11:56+00:00 2026-06-14T12:11:56+00:00

My need is to generate buttons with conditions described in json. Help me please,

  • 0

My need is to generate buttons with conditions described in json. Help me please, I’m newbie and I’m stuck. The problem is that my code generates buttons with text “undefined” and nothing happens on button click.

Here is my JSON code (it is valid due to check result at http://www.jsoneditoronline.org/ , but does not work with html code below):

    {
        "Caption": "Module caption",
        "IconsDirectory": "C://Images/",
        "Buttons": [
            {
                "Conditions": [
                    {
                        "ConditionText": "1 == 1",
                        "ButtonText": "Text1",
                        "Visible": true,
                        "Colors": {
                            "FontColor": "#FFFFFF",
                            "BGColor": "#669933"
                        },
                        "BButtonText": {
                            "TText": "Textt1"
                            },
                        "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": "#0FFFFF",
                            "BGColor": "#FF9966"
                        },
                        "BButtonText": {
                            "TText": "Textt1"
                            },
                        "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.Conditions[0].JavaScriptAction +'" value="'+ val.Conditions[0].ButtonText +'"/>        </li>').appendTo('#ulObj');
                //$('<li><input type="button" value="'+         val.Conditions[1].BButtonText.TText +'"/></li>').appendTo('#ulObj');
    var res=""
    $.each(data.Buttons, function(key, button){
        $.each(button.Conditions,function(key,condition){
        //  console.log(condition)
            res+="<li>"
            res+='<input type="button"' + 
                //'" value="'+ '"Ttt"' +
                '" value="'+ condition.ButtonText +
                //'" value="'+ data.Buttons.Conditions.ButtonText +
                '" onclick="' + condition.JavascriptAction +
                '" style="background-color:'+condition.Colors.BGColor+'         color:'+condition.Colors.FontColor+
                '"/>'
            res+="<\/li><\/br><\/br>test<\/br>"
        })
    })
    $(res).appendTo('#ulObj')

               //});
       });             
         });

    window.onload = function(){ alert("welcome"); }

       </script>
    </head>
    <body bgcolor="silver">
    <br>
    <br>
    <div>
    <ul id='ulObj'>
    <li>1</li>
    <li>2</li>
    <li>3</li>
    </ul>
    </div>
    </body>
    </html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T12:11:58+00:00Added an answer on June 14, 2026 at 12:11 pm

    onClick handler should be condition.JavaScriptAction.Text. Rest everything was working fine.

    var res = ""
        $.each(data.Buttons, function(key, button) {
            $.each(button.Conditions, function(key, condition) {
                res += "<li>"
                res += '<input type="button"' + '" value="' + condition.ButtonText + '" onclick="' + condition.JavaScriptAction.Text + '" style="background-color:' + condition.Colors.BGColor + '         color:' + condition.Colors.FontColor + '"/>'
                res += "<\/li><\/br><\/br>test<\/br>"
            })
        })
        $(res).appendTo('#ulObj')
    

    http://jsfiddle.net/x8Ysd/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to generate report that will show number of new / changed rows
I need to generate some token that can only take on a range of
I already have the code I need to get button labels/number of buttons off
There are 2 buttons which will generate 2 piece of data. What I need
I need to generate a grid of buttons for an iOS app. Each button
I'm using the code in this answer to generate a grid of buttons. When
I need to create a question wizard with the help of ViewFlipper so that
I need to generate a custom button through code, this is how i am
i need some help with this, i'm trying to generate some html with javascript,
My need is to generate buttons with specified parameters only if condition is true.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.