Welcome to the nuBuilder Forums!

Join our community by registering and logging in.
As a member, you'll get access to exclusive forums, resources, and content available only to registered users.

Assign a value to a variable field of an HTML object within a subform

Questions related to customising nuBuilder Forte with JavaScript or PHP.
Post Reply
cuadradoja
Posts: 29
Joined: Thu Sep 01, 2022 3:42 am
Has thanked: 1 time

Assign a value to a variable field of an HTML object within a subform

Unread post by cuadradoja »

Hello,

I have an HTML object in a subform to display a gauge chart. Within the subform, I also have a field called ind_rango, where any value can be entered to be displayed with the image. I can do this process in a normal form without any problems, but when I try to do it within a subform, it doesn't work. The question I have about this is how I should express the variable: var ir so that the value entered can be displayed in the HTML object. The code I use is the following:

Code: Select all

<!DOCTYPE html>
<html>
<head>
    <title>Indicador</title>
    <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
    <script type="text/javascript">
        
        var ir = parseFloat(nuSubformRowObject(event.target.id, 'ind_rango').val());
        
        google.charts.load('current', {
            'packages': ['gauge']});
        google.charts.setOnLoadCallback(drawChart);

        function drawChart() {
            var data = google.visualization.arrayToDataTable([
                ['Label', 'Value'],
                ['%', ri]
            ]);
            
            var options = {
                width: 400,
                height: 200,
                max: 120,
                redFrom: 0,
                redTo: $r1,
                yellowFrom: $r1,
                yellowTo: 70,
                greenFrom: 70,
                greenTo: 100,
                blueFrom: 100,
                blueTo: 120,
                yellowColor: "#FFFF93",
                redColor: "#FF3300",
                greenColor: "#99FF33",
                minorTicks: 5,
                titleTextStyle: {
                    fontSize: 4
                }
            };
            var chart = new google.visualization.Gauge(document.getElementById('chart_div'));
            chart.draw(data, options);
        }
    </script>
</head>
<body>
    <h1>"% decrease"</h1>
    <style>
        h1 {
            font-size: 12px;
        }
    </style>
    <div id="chart_div" style="width: 400px; height: 200px;"></div>
</body>
</html>
kev1n
nuBuilder Team
Posts: 4447
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 75 times
Been thanked: 489 times
Contact:

Re: Assign a value to a variable field of an HTML object within a subform

Unread post by kev1n »

Hello,

You declared a variable as ir, but you're using ri instead.
cuadradoja
Posts: 29
Joined: Thu Sep 01, 2022 3:42 am
Has thanked: 1 time

Re: Assign a value to a variable field of an HTML object within a subform

Unread post by cuadradoja »

Hello again kev1n...

That's true, I adjusted it, but it still doesn't show the value I specified. In fact, it doesn't display any image through the object. :?
Post Reply