Re: Run php code onclick?
Hi :)
is your code similar to this?
HTML Code:
<a href="some url" onclick="doit();">click here</a>
if true, then the browser would navigate to the required URL, try something like this
HTML Code:
<a href="some url" onclick="return false;doit();">click here</a>
the "return false" should fire when the user hits click, it doesn't mean anything inside the doit() function.
Re: Run php code onclick?
Hi Mate
Thanks for your reply,
Altough, the code you provided does not seem to fix the issue :( it seems that every time the div gets refreshed it will run
Code:
<script type="text/javascript">
function doit()
{
$.get("http://weloveradio.co.uk/site/wp-content/themes/main/updatenotifications.php");
return false; }
</script>
Its confusing me a lot! Any other ideas as why it could be causing it everytime the div tag gets refreshed?
Re: Run php code onclick?
don't worry your problem is easy to solve :), but let me please understand your required scenario, do you want the div content to refresh itself automatically? or just when user click on the link or both?
anyway, this is a simple example where content will be refreshed only when user hits refresh link
HTML Code:
<script type="text/javascript">
$(document).ready(function(){
$(".refresh").click(function(){
$.get("ajax.php", function(result){
$("#div").html(result).fadeIn('slow');
});
});
});
</script>
<div id="div"></div>
<a href="" onclick="return false;" class="refresh">refresh</a>
and this is another example where content will refresh automatically every 10 seconds using timeout with timerID and will refresh when user hits refresh too
note: when user hits refresh the timer would reset and wait new 10 seconds
HTML Code:
<script type="text/javascript">
$(document).ready(function(){
var autoRefresh = window.setTimeout("loadData()", 10000);
$(".refresh").click(function(){
window.clearTimeout(autoRefresh);
loadData();
});
});
function loadData()
{
$.get("ajax.php", function(result){
$("#div").html(result).fadeIn('slow');
});
autoRefresh = window.setTimeout("loadData()", 10000);
}
</script>
<div id="div"></div>
<a href="" onclick="return false;" class="refresh">refresh</a>
good luck,
Feras Jobeir