by Blakos
4 replies
Firstly, thank you for helping me with my Pickle

Let me start off by trying to explain what I am trying to do:

I am trying to create a button(at this current point of time it is a link) of which may be clicked by a user visiting my website, and once the button is clicked it disappears(well the division disappears) using .hide() in JQuery.
Problem is I am counting the clicks in PHP, and stuck trying to call the Javascript function after the PHP calls the counting page, then reloads the index(<--- This is when I need that function called...)

I also want to use localStorage in Javascript to keep the element(button) hidden after it is clicked, even if they reload the page, can anybody give me some examples on that one also please?

Here are my script/s:

root/index.php:

Code:
<!DOCTYPE html>
<html lang="en">
<head>
    <?php include 'includes/functions.php'; ?>

    <script type="text/javascript" src="scripts/jquery.js"></script>

    <script type="text/javascript" src="scripts/javascript.js"></script>
    
</head>
<body>

    <div id="button">
        <a href="join.php?click=1" onclick="hideButton()">JOIN HERE</a><br>
        <?php echo $get_count;?> people have joined simply by clicking the link above!
    </a>
    
</body>
</html>
root/join.php:

Code:
<?php

$click = $_REQUEST['click'];
        
$file_location = 'clicks.ini';
$update_hits = file($file_location);

$update_count = ($update_hits[0] + 1);
$get_file = $file_location;
$handle_file = fopen($get_file, 'w');
$return_data = "$update_count";
fwrite($handle_file, $return_data);
fclose($handle_file);

echo '<meta http-equiv="refresh" content="0; url=index.php">';

?>


root/
includes/functions.php:

Code:
<?php

//Click Data
$file_location = 'clicks.ini';
$get_hits = file($file_location);
$get_count = ($get_hits[0]);

?>
root/scripts/javascript.js:

Code:
//Hide Button
function hideButton() {
    $('#button').hide();
}
Thanks in advanced
#bit #pickle
  • Profile picture of the author Marc Quarles
    Ajax.

    Use an ajax call to signal the PHP script to do what it needs to do, then hide the button without reloading the page.
    {{ DiscussionBoard.errors[8157961].message }}
    • Profile picture of the author Blakos
      Originally Posted by Marc Quarles View Post

      Ajax.

      Use an ajax call to signal the PHP script to do what it needs to do, then hide the button without reloading the page.
      Thank you for your input.

      Although I am treading on thin ice with PHP and AJAX at the moment as I have not really worked with them properly until now.

      Could you possible show me a bit of code so I can understand what I need to do?


      Thanks in advanced.
      {{ DiscussionBoard.errors[8158313].message }}
  • Profile picture of the author Michael71
    Yeah, jQuery .ajax() would be a good option.

    BTW, there is NO need to use HTML5 Local Storage for a simple "function" that hides the button. Local Storage is not made for those simple stuff.

    Using cookies is really one of the common options.
    Signature

    HTML/CSS/jQuery/ZURB Foundation/Twitter Bootstrap/Wordpress/Frontend Performance Optimizing
    ---
    Need HTML/CSS help? Skype: microcosmic - Test Your Responsive Design - InternetCookies.eu

    {{ DiscussionBoard.errors[8159405].message }}

Trending Topics