php - What's wrong with this onClick? Javascript -


i've been dealing half day this. function not working. worked @ 1 point , can't figure out how go back. html code

<a href="#" onclick="updatedb('<?php echo $a; ?>','<?php echo $b; ?>','<?php echo $c; ?>','<?php echo    $d; ?>','<?php echo $e; ?>','<?php echo $f; ?>','<?php echo $g; ?>','<?php echo $h; ? >','<?php echo $i; ?>','<?php echo $j; ?>','<?php echo $k; ?>')">test</a> 

here javascript code

<script>     $(function() {     function updatedb(a,b,c,d,e,f,g,h,i,j,k)    {         $.post("update.php",         { a:a,b:b,c:c,d:d,e:e,f:f,g:g,h:h,i:i,j:j,k:k          });      alert("finally");    }  } </script> 

i can't finally.

any appreciated.

thanks,

because using <a> tag, need stop default execution of such link. easiest be:

onclick="updatedb(...); return false;" 

that being said, since use jquery, favor , use jquery's event handlers, e.g:

<a href="#" id="testlink">test</a>  <script>     $('#testlink').click(function(event){         event.preventdefault();         updatedb('<?php echo $a; ?>','<?php echo $b; ?>','<?php echo $c; ?>','<?php echo   $d; ?>','<?php echo $e; ?>','<?php echo $f; ?>','<?php echo $g; ?>','<?php echo $h; ?>','<?php echo $i; ?>','<?php echo $j; ?>','<?php echo $k; ?>');     }); </script> 

even better attach variables php , add them data- attribute, can reuse click handler:

<a href="#" class="testlink" data-my-value="1">test 1</a> <a href="#" class="testlink" data-my-value="2">test 2</a>  <script>     $('.testlink').click(function(event){         event.preventdefault();         var data = $(this).attr('data-my-value');         updatedb(data);     }); </script> 

update: still redirect page, (untested):

<a href="newpage.html" class="testlink" data-my-value="1">test 1</a>  <script>     $('.testlink').click(function(event){         event.preventdefault();         var data = $(this).attr('data-my-value'),             url = $(this).attr('href');         updatedb(data, url);     });      function updatedb(data, url)     {         $.post("update.php",             data,              function() {                 window.location = url;             }         );     } </script> 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -