I was wondering if some one could point me in the right direction with making an image show how many times it's been clicked.

Recommended Answers

All 5 Replies

Member Avatar for rajarajan2017
<html>
<head>
<title>
Event Handler with multiple statement</title>
<script language="javascript">
function cnt()
{
	var count=parseInt(document.frm1.inp1.value);
	count++;
	document.frm1.inp1.value=count;
	alert(document.frm1.inp1.value);
}
</script>
</head>
<body>
<form name="frm1" method="post" action="">
<h1>Evet Handler with multiple statements</h1>
<p>Displays the number of times you click on your image.</p>
<img src="test.jpg" onClick="cnt()"/>
<input type="hidden" name="inp1" value="0"/>
</form>
</body>
</html>

just increment it everytime it clicks and save it to database

try this

<?php
//Please set the following variables for your mysql database:
$db_hostname = "localhost";  //usually "localhost be default"
$db_username = "root";  //your user name "I use root"
$db_pass = "";  //the password for your user "root folder have not password"
$db_name = "Your Database Name";  //the name of the database


/*MYSQL DATABASE CONNECTION/ TRACKING FUNCTIONS
--------------------------------------*/
// connect to database
$dbh = mysql_connect ($db_hostname, $db_username, $db_pass) or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ($db_name);

// get value from hidden feild
$table_name = $_POST["inp1"];

// select value from dtabae
$getData = mysql_query("SELECT table_name FROM Data_Feild"); 
$num_rows = mysql_num_rows($getData);

if($num_rows==0)
{
	$writeData = mysql_query("INSERT INTO table_name (column1) VALUES ($table_name)" );

}
else if ($num_rows > 0){
	$writeData = mysql_query('UPDATE table_name SET column1 ="'.$table_name.'"');
}
else{
	mysql_error();
}

}
?>

<html>
<head>
<title>
Event Handler with multiple statement</title>
<script language="javascript">
function cnt()
{
	var count=parseInt(document.frm1.inp1.value);
	count++;
	document.frm1.inp1.value=count;
	//alert(document.frm1.inp1.value);
}
</script>
</head>
<body>
<form name="frm1" method="post" action="">
<h1>Evet Handler with multiple statements</h1>
<p>Displays the number of times you click on your image.</p>
<img src="test.jpg" onClick="cnt()"/>
<input type="hidden" name="inp1" value="0"/>
<input type="submit" name="submit" value="Submit"/>
</form>
</body>
</html>

cheers

commented: Thanks! +0

Thanks guys, but what I really want to do is show the amount of clicks on the image itself.

So the image will say "I've been clicked X times! Please click me!"

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.