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 8154141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:14:33+00:00 2026-06-06T16:14:33+00:00

Hey friends any one please help me for this issue.in this javascript code i

  • 0

Hey friends any one please help me for this issue.in this javascript code i m getting 2 arrays IDs array and percentage array from controller and convert them into javascript array now i wana dynamically changing css property of an element but i need succeed.If anyone find error in this code please tell me

@section javascript{
        <script  type="text/javascript">
         $(document).ready(function() {
                @{
                    string data = "";
                    int length = ViewBag.length;
            }

              var percent = new Array();
            @for (int j = 0; j < length; j++)
            {
                data += "percent[" + j + "]=\"" + ViewBag.percentage[j] + "\";";
            }         
             @MvcHtmlString.Create(data);  
              var ids = new Array();
            @for (int i = 0; i < length; i++)
            {   
                data += "ids[" + i + "]=\"" + ViewBag.IDs[i] + "\";";
            }   
              @MvcHtmlString.Create(data);
             //get current date day for javascript
            var date  = new Date();
            var day = date.getDay();
            var dayper = (day/30)*100;
            //**************************************************************//
            //Remaining amount in percentage variable as percent[i] is spend//
            //amount percentage so subtracting spend percentage from 100 wil//
            // return remaing amount percentage                             //
            //**************************************************************//
            var rA;
            var per;
            var id;
             for(var k = 0;k<ids.length;k++)
             {
                per = percent[k];
                id  = ids[k];
                document.getElementById(id).style.width = parseInt(per)+"%";
                rA = 100 - parseInt(percent[k]);
                if(rA - dayper > 40)
                {
                    document.getElementById(id).style.background = "red";
                }
                else if((rA - dayper)>20 && (rA - dayper) < 40)
                {
                    document.getElementById(id).style.background = "yellow";
                }           
                else
                document.getElementById(id).style.background = "green";
             }            
          });


        </script>
  • 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-06T16:14:36+00:00Added an answer on June 6, 2026 at 4:14 pm

    What you have shown is an absolutely horrible mixture of server side and client side code. Sorry to say it but that’s abominable code. Please separate those concerns. Also since you seem to be already using jQuery, I cannot find any reasonable explanation of why you are not taking advantage of it, but writing some à la 90s javascript code.

    So let’s see how we could improve this:

    @section javascript {
        <script type="text/javascript">
            $(document).ready(function() {
                var percents = @Html.Raw(Json.Encode(ViewBag.percentage));
                var ids = @Html.Raw(Json.Encode(ViewBag.IDs));
    
                var date  = new Date();
                var day = date.getDay();
                var dayper = (day / 30) * 100;
    
                $.each(ids, function(index, id) {
                    var percent = parseInt(percents[index], 10);
                    var element = $('#' + id);
                    element.css('width', percent + '%');
                    var rA = 100 - percent;
                    var color = 'green';
    
                    if (rA - dayper > 40) {
                        color = 'red';
                    } else if (rA - dayper > 20 && rA - dayper < 40) {
                        color = 'yellow';
                    }
    
                    element.css('background-color', color);
                });
            });
        </script>
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey friends can you help me out with this issue. I have a JSON:
Hey guys this is my html code: <div class=nakupy> <li class=icn_kategorie><a href=#>Nákupy</a> <div class=sub_menu>
Hey, say you have an array of friends that you've retrieved, how can you
Hey friends I have one problem related to SQL Server 2008 R2. I set
hey. friends i dont know this question is really asked before or not ?
Hey guys here is my php: $x = array(one, two, three); foreach ($x as
Hey, i need a little help with this django function. I wan't to insert
hey friends, i have been assigned a query planning project. in this project if
Hey Friends i got all contacts detail of my iphone by using this function
Hey Friends, I am using the following API for getting details of IMDB,http://www.deanclatworthy.com/imdb/?q=Star+Trek while

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.