Click here to Skip to main content
15,890,897 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have following repeater

<script type="text/javascript">
        var markers = [];
        <asp:Repeater ID="rptMarkers" runat="server">
            <ItemTemplate>
                    markers.push({"Start": '<%# Eval("START") %>',"Fixed_Tax": '<%# Eval("FIXED_TAX") %>',"Rate": '<%# Eval("RATE") %>',"W_E_F": '<%# Eval("W_E_F") %>'});
            </ItemTemplate>
        </asp:Repeater>
    </script>


and the console window while debugging lookgs like this

<script type="text/javascript">
        var markers = [];
        
                    markers.push({"Start": '7000001',"Fixed_Tax": '1422000',"Rate": '0.3',"W_E_F": '1/1/1970 12:00:00 AM'});
            
                    markers.push({"Start": '4000001',"Fixed_Tax": '597000',"Rate": '0.275',"W_E_F": '1/1/1970 12:00:00 AM'});
            
                    markers.push({"Start": '3500001',"Fixed_Tax": '472000',"Rate": '0.25',"W_E_F": '1/1/1970 12:00:00 AM'});
            
                    markers.push({"Start": '3000001',"Fixed_Tax": '359500',"Rate": '0.225',"W_E_F": '1/1/1970 12:00:00 AM'});
            
                    markers.push({"Start": '2500001',"Fixed_Tax": '259500',"Rate": '0.2',"W_E_F": '1/1/1970 12:00:00 AM'});
            
                    markers.push({"Start": '1800001',"Fixed_Tax": '137000',"Rate": '0.175',"W_E_F": '1/1/1970 12:00:00 AM'});
            
                    markers.push({"Start": '1500001',"Fixed_Tax": '92000',"Rate": '0.15',"W_E_F": '1/1/1970 12:00:00 AM'});
            
                    markers.push({"Start": '1400001',"Fixed_Tax": '79500',"Rate": '0.125',"W_E_F": '1/1/1970 12:00:00 AM'});
            
                    markers.push({"Start": '750000',"Fixed_Tax": '14500',"Rate": '0.1',"W_E_F": '1/1/1970 12:00:00 AM'});
            
                    markers.push({"Start": '500000',"Fixed_Tax": '2000',"Rate": '0.05',"W_E_F": '1/1/1970 12:00:00 AM'});
            
                    markers.push({"Start": '400001',"Fixed_Tax": '0',"Rate": '0.02',"W_E_F": '1/1/1970 12:00:00 AM'});
            
                    markers.push({"Start": '0',"Fixed_Tax": '0',"Rate": '0',"W_E_F": '1/1/1970 12:00:00 AM'});
            
    </script>


Please help me how can i access the values using javascript of this repeater

What I have tried:

Searched and tried different things but did not work
Posted
Updated 27-Feb-18 4:00am
Comments
Karthik_Mahalingam 27-Feb-18 9:36am    
use the 'markers' object to access the items.
Faran Saleem 28-Feb-18 23:59pm    
Can you give an example? how should i access the value 700001

1 solution

The "markers" variable is useable from anywhere, the only caveat is that js is processed as the page is rendered so you can use the variable after it is defined but not before

<script type="text/javascript">
    alert (markers.length); // CAN'T use it here
</script>
<script type="text/javascript">
        var markers = [];
        <asp:Repeater ID="rptMarkers" runat="server">
            <ItemTemplate>
                    markers.push({"Start": '<%# Eval("START") %>',"Fixed_Tax": '<%# Eval("FIXED_TAX") %>',"Rate": '<%# Eval("RATE") %>',"W_E_F": '<%# Eval("W_E_F") %>'});
            </ItemTemplate>
        </asp:Repeater>
    </script>
<script type="text/javascript">
    alert (markers.length); // Can use it here
</script>


You can move your code block to the top of the page if it helps.
 
Share this answer
 
Comments
Faran Saleem 28-Feb-18 23:55pm    
What i want to know is how can i access the values.
Like if i want to access 700001 then how should i get it in a javaScript variable.
I am doing markers[0] but not working
F-ES Sitecore 1-Mar-18 4:54am    
markers[0].Start
Faran Saleem 2-Mar-18 2:41am    
Thanks it worked and can you please tell me how can i calculate the tax based on gross income?
lets say if the income entered is 50000 then it should select the nearest start row with 50000 which is 75000 and then will calculate the income based on below formula,
tax_income =(((res[0].GINCOME * 12) - start) * rate + v_tfx / 12);

Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900