1

I have created an empty array at the beginning of the form

<script>
   var monthly_values = [];
   var i=0;
</script>

Inside the loop trying to achieve below code.... but the push doesn't work without "alert" box nor if i remove "ready(function())"

$prodline=500$    /// CGI script loops till 500 iterations 
<script>
 $(document).ready(function(){
     i++;
     monthly_values.push("$premium$");
     setTimeout(function() { 
       alert("$premium$");
     }, 1);

 });
</script>
 $/prodline$//end of the iteration...

I push values from loop into array which is working .But i need to remove alert box or at least OK from alert box ..

The Entire Code is here..

    <html>
    <head>
      <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js"></script>
       <title>PHP FILE  - $licensee$</title>
       <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">   
       <meta name="Author" content="COMPULIFE Software, Inc.">
       <link href="../../css/styles_website.css" type="text/css" rel="stylesheet">
       <link href="../../css/termsampler.css" type="text/css" rel="stylesheet">
       <link href="../../css/$css$" type="text/css" rel="stylesheet"> 
    <script>
         var monthly_values = [];
         var i=0;
    </script>

    <script language="JavaScript" type="text/javascript">
      //     var monthly_values = [];
         // var i=0;
    function getbest (ambest, company, compcode)
    {
      document.comparisonform.AmBest.value = ambest;
      document.comparisonform.CompanyName.value = company;
      document.comparisonform.CompanyCode.value = compcode;
      document.comparisonform.OnClick=abc=window.open('','reason','width=700,height=500,left=20,top=20,scrollbars=yes');
      document.comparisonform.target='reason';
      abc.focus();
      document.comparisonform.submit();
    }
    </script>  
    </head>
    <body>
    </tr>
    <style>
    .loader {
      border: 16px solid #f3f3f3;
      border-radius: 50%;
      border-top: 16px solid #3498db;
      width: 120px;
      height: 120px;
      -webkit-animation: spin 2s linear infinite;
      animation: spin 2s linear infinite;
      margin: auto;
      padding: 10px;
    }

    @-webkit-keyframes spin {
      0% { -webkit-transform: rotate(0deg); }
      100% { -webkit-transform: rotate(360deg); }
    }

    @keyframes spin {
      0% { transform: rotate(0deg); }
      100% { transform: rotate(360deg); }
    }
    </style>
    </head>
    <body>
    <div class="loader" style ></div>
    $prodline=500$

    <script>
      $(document).ready(function(){
        i++;
        monthly_values.push("$premium$");
        setTimeout(function() { 
          alert("$premium$"+"$company$"+"$product$"+"$healthcat$"+"$PremiumAnnual$"+"$Premium$"+"$rgpfpp$"+"$guar$"+"$policyfee$"+"$comp$"+"$prod$"+"$rowEvenOdd$");
        }, 1);

      });
    </script>
    $/prodline$
    </table>

    </form>

    <br><br>

    <script>
      $(document).ready(function(){

        var len=monthly_values.length;
        var min_quote=monthly_values [0];
          var max_quote=monthly_values [monthly_values.length-1];

        window.location = 'http://loalhost/laravel/public/customised-quote?min_quote_val='+min_quote+'&max_quote_val='+max_quote;
      });
    </script>
10
  • what is $premium$ and which type output you need Commented Nov 17, 2017 at 7:47
  • its float value eg. 73.35,104.40 Commented Nov 17, 2017 at 7:48
  • "remove alert box or at least OK from alert box"... just remove alert from setTimeout Commented Nov 17, 2017 at 7:48
  • @Beginner that not php variable and its printing the values without any issues Commented Nov 17, 2017 at 7:50
  • maybe what he means is prepend Commented Nov 17, 2017 at 7:50

1 Answer 1

1

This code should work without problems, check the snippet below. Are you including jQuery in your html?

var monthly_values = [];
var i=0;
 
 $(document).ready(function(){
     i++;
     monthly_values.push("$premium$");
     setTimeout(function() { 
      console.log(monthly_values)
     }, 1);

 });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

EDIT after seeing your updated code, if i understand it right, in your loop you are rendering the the document $(document).ready() snippet 500 times, which is completely wrong approach.

Not sure what language you are using, and what exactly are you trying to achieve with your loop, but you could just print your $prodline$ array directly into javascript array variable without having to loop through it

Also, now i noticed in your $(document).ready() at the end of your file you are redirecting to new url immediately, if this is your intended result, generate the array just before you redirect like this:

<script>
$(document).ready(function(){
    var monthly_values = []

$prodline=500$
    monthly_values.push("$premium$")
$/prodline$

    var len=monthly_values.length;
    var min_quote=monthly_values [0];
    var max_quote=monthly_values [monthly_values.length-1];

    window.location = 'http://localhost/laravel/public/customised-quote?min_quote_val='+min_quote+'&max_quote_val='+max_quote;

})
</script>
Sign up to request clarification or add additional context in comments.

9 Comments

Sorry empty ARRAY :(
I don't see how it's empty I tried this snippet and this working fine
Please post your full code including the loop. Are you trying to do this with PHP and $premium is a PHP variable?
yes i tired that at the end of operation im feting the first and last values from array where it give empty .. but practically this code should work ... and even if i remove alert it should work ...
@mike_t i have added the loop at the question thanks for your time
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.