Jump to content

problem in loop - JS


felito

Recommended Posts

hi

 

i have many pieces of code like:

    <script type="text/javascript">
    dojo.query("body").delegate("#input0 > select.estatistica", "onchange", function(evt){
            dojo.xhrPost({
                url: "drop2.php",
                handleAs: "json",
                postData: "data=" + $(this).val(),
                preventCache: true,
                load: function(json) {
                    $m0 = [];
    
                    for (var i = 1; i < 10; i++) {
                        $m0.push(parseFloat(json[i]["valor" + i]));
                    }
                    dojo.addOnLoad(refreshChar0);
    
                }
            });
        });
    </script>
    
    

    <script type="text/javascript">
    dojo.query("body").delegate("#input1 > select.estatistica", "onchange", function(evt){
            dojo.xhrPost({
                url: "drop2.php",
                handleAs: "json",
                postData: "data=" + $(this).val(),
                preventCache: true,
                load: function(json) {
                    $m1 = [];
    
                    for (var i = 1; i < 10; i++) {
                        $m1.push(parseFloat(json[i]["valor" + i]));
                    }
                    dojo.addOnLoad(refreshChart1);
                }
            });
        });
    </script>

 

 

i tried this loop, but i am not sure about the script. Probably i have syntax errors. Correct?

    <script type="text/javascript">
    for(x=0; x<10; x++) {
    	dojo.query("body").delegate("'#input'+x > select.estatistica", "onchange", function(evt){
            dojo.xhrPost({
                url: "drop2.php",
                handleAs: "json",
                postData: "data=" + $(this).val(),
                preventCache: true,
                load: function(json) {
                    $m+x = [];
    
                    for (var i = 1; i < 10; i++) {
                        $m+x.push(parseFloat(json[i]["valor" + i]));
                    }
                    dojo.addOnLoad(refreshChart+x);
                }
            });
        });
    }
    </script>

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/236408-problem-in-loop-js/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.