javascript - Trying to define a function inside onclick -


i trying define function inside onclick. not working , no error showing on console. have called function bottom of page , have defined function inside onclick() not working.

 <div id="content-wrapper">            <div class="row">             <div class="col-lg-12">             <div class="main-box clearfix">             <div class="clearfix">               <div class="common_page gsb1">               <div class="hdr">                    <div class="row">                 <div class="col-md-4">                   <h4>users</h4>                 </div>                  <div class="col-md-5"> //this not working     <p><a href="" onclick="function send_data(data){                     download_csv(data)};">download </a></p>                 </div>                    <div class="col-md-3 pull-right">                       <%=render 'search'%>                 </div>                </div>                          </div>              <% download_data = []%>                <%@users.each |user|%>                        <div id='content' class="tab-content">                     <div class="tab-pane active" id="all">                       <div class="row">                       <div class="col-md-4">                         <p><b>user name</b> <span class="blue"> <%=user.name %> </span> </p>                         <%download_data.push(user.name)%>                        <p><b>user_code</b> <span class="blue"> <%=user.user_code %> </span>  </p>                          <%download_data.push(user.user_code)%>                        <p><b>phone</b> <span class="blue"><%=user.phone %></span>  </p>                         <%download_data.push(user.phone)%>                      </div>                    </div>                </div>                <%end%>                <div data-no-turbolink>                 <%if @users.length > 1%>                   <%= will_paginate @users %>                 <% end %>               </div>                   </div>               </div>               </div>             </div>           </div>            <footer id="footer-bar" class="row">             <p id="footer-copyright" class="col-xs-12">               powered abcadas             </p>           </footer>         </div>       </div>     </div>   </div>   <script >        $("#zsales").attr("class","active")         send_data("<%=download_data%>")   </script> 

onclick="function send_data(data){                 download_csv(data)};">download </a></p> 

you're doing in opposite way. should call function on onclick, , define elsewhere. this:

<p><a href="" onclick="send_data()">download </a></p> 

and in script:

<script >    $("#zsales").attr("class","active")     function send_data(data){        download_csv(data);    }; </script> 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -