Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 11
  1. #1
    Member
    Join Date
    Aug 2006
    Posts
    67
    Member #
    13752
    Hi.

    I have been asked to setup a petition page where a user checks a check box, presses a submit button and a counter displays how many time the button has been pressed.

    Essentially the most important thing is to count the amount of times the buttom has been pressed.

    Initially there is no database involved. So i am assuming using javscript is the best way to go about it.

    Can someone point me in the right direction?
    either that or i may have to go out and buy a javascript book.

    cheers!

  2.  

  3. #2
    Senior Member hyperair's Avatar
    Join Date
    May 2005
    Posts
    452
    Member #
    9892
    I've a question: how do you intend to keep track of the clicks without using a database? Unless everyone who wants to click the button comes to ONE specific computer to click it, it won't work. You'll need a database/text file and a server-side script.
    Hyperair

  4. #3
    Member
    Join Date
    Aug 2006
    Posts
    67
    Member #
    13752
    hmmm. i was concerned about that. I thought there might be a way of storing counter variable as a cookie or something.
    To be honest im very new to web design and havent really got my head around this sort of thing yet.

    So basically i need a database?

    Thanks.

  5. #4
    Senior Member hyperair's Avatar
    Join Date
    May 2005
    Posts
    452
    Member #
    9892
    Yes, that's right. WIthout a database you can only record how many times the button is clicked on ONE computer.
    Hyperair

  6. #5
    Member
    Join Date
    Aug 2006
    Posts
    67
    Member #
    13752
    could i not just write a small piece of code that will allow the user to press the button only when the checkbox has been checked. Then on the thank you page (using formail), use a free hit counter to display how many hits there are.

    Im not too worried about accuracy or good practices as this is not for any commercial use.

    cheers.

  7. #6
    Senior Member hyperair's Avatar
    Join Date
    May 2005
    Posts
    452
    Member #
    9892
    Well, I must say that this is a rather..... creative way of doing things. But yes it would work. There's the risk of users voting multiple times by refreshing the page and so on, but other than that it should be fine =\

    What's formail anyway?
    Hyperair

  8. #7
    Member
    Join Date
    Aug 2006
    Posts
    67
    Member #
    13752
    well ill give it a go and see what happens :-)

    formail is script which lets u send form data directly to an email address.

    thanks!

  9. #8
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    If you don't want to do it with a database, you can use PHP and store the number in an INI file. You have to make sure that PHP has file writing permissions on the folder where your INI file is stored. But assuming you can handle that, this is a cut and paste script.

    Here's what I made for you...

    http://www.transio.com/simple_survey/survey.html

    (The files are also attached in a zip)

    This is what your form would look like:
    Code:
    <html>
        <head>
            <title>Form</title>
            <style type="text/css">
                label {
                    font-weight: bold;
                    display: block;
                    margin-bottom: 5px;
                }
            </style>
        </head>
        <body>
            <form action="survey.php" method="post">
                <label for="question">Ain't Transio the best?</label>
                <input type="radio" name="question1" value="yes" />Yes!!!<br />
                <input type="radio" name="question1" value="no" />Not Really.<br />
                <input type="radio" name="question1" value="maybe" />Meh... maybe.<br />
                <input type="submit" value="Submit" />
            </form>
        </body>
    </html>
    This is what survey.php would look like:

    PHP Code:
    <?php
        
    // Start a session
        
    session_start();

        
    // Set the filepath for this server (I'm using a subdirectory called "simple_survey")
        
    $filePath $_SERVER['DOCUMENT_ROOT'] . "/simple_survey";

        
    // Get the survey results    
        
    $surveyResults parse_ini_file($filePath."/survey_results.ini");

        
    // Check if the user already answered the question during this visit
        
    if (isset($_POST["question1"])) {
            if (
    $_SESSION["answered"]) {
                
    $message "You already answered the question.";
            } else {
                
    $key "answered_" $_POST["question1"];
                if (isset(
    $surveyResults[$key])) {
                    
    // Increment the result value
                    
    $surveyResults[$key] ++;
        
                    
    // Write the results back to the INI file
                    
    $fh fopen($filePath."/survey_results.ini""w");
                    
    fwrite($fh"[question1]\n");
                    foreach (
    $surveyResults as $key => $value) {
                        
    fwrite($fh"{$key} = {$value}\n");
                    }
                    
    fclose($fh);
        
                    
    // Don't allow this user to answer again during this session
                    
    $_SESSION["answered"] = true;
        
                }
            }
        }
    ?>
    <html>
        <head>
            <title>Results</title>
        </head>
        <body>
            <h1>Survey Results</h1>
            <?php
                
    if (isset($message)) echo("<p>{$message}</p>");

                echo(
    "<dl>");
                foreach (
    $surveyResults as $key => $value) {
            
    $key substr($key9);
                    echo(
    "<dt>{$key}</dt>");
                    echo(
    "<dd>{$value}</dd>");
                }
                echo(
    "</dl>");
            
    ?>
        </body>
    </html>
    Here's how you would set up your INI file the first time:
    Code:
    [question1]
    answered_yes = "0"
    answered_no = "0"
    answered_maybe = "0"
    By using sections, we can even set it up for multiple questions. You would have to use parse_ini with section-parsing on, though... not necessary for this tool.

    The main drawback to this will be that you can't thread or lock the file to prevent overwriting / loss of data if multiple people submit simultaneously. This will only be a problem when you have thousands of visitors per day, though, so the file system should work fine for you for now.

  10. #9
    Member
    Join Date
    Aug 2006
    Posts
    67
    Member #
    13752
    wow. that looks like quite an advanced way of doing it.
    I think i may come back to your sugguestion at a later time.

    At the moment what i am trying to do is write some javascript code which will only allow the form to be submitted if the checkbox is checked.

    can anyone sugguest how i can do this?

    i made an attempt although i havent really use javascript before so i am having to piece bits together off the net.

    This is what i have so far.

    Code:
        <head>
            <title>Petition</title>
    <script type="text/javascript">/* <![CDATA[ */  
    function checkBoxCheck()
    {
        if (document.getElementById("check_box").disabled=true)
            alert("Please tick the box provided");
        else return;
    }
    
    /* ]]> */ 
     </script> 
    
        </head>
        <body>
    <div align="center">
    <form method="post" action="formmail.php">
    <table border="0" cellpadding="10" width="500">
    <tr><td colspan="2"><img src="eidfinal.jpg" width="500" height="107" alt="logo"></td></tr>
    <tr><td colspan="2"><input type="hidden" name="recipient" value="jamie@nuvibes.com" /></td></tr>
    <tr><td>Email:</td><td><input type="text" name="email" size="40"></td></tr>
    <tr><td>Please Tick the Box:</td><td><input type="checkbox" name="checked" id="check_box"></td></tr>
    <tr><td><input type="submit" value="Submit" onSubmit="return checkBoxCheck()"></td>
    <td><input type="reset" value="Reset"></td></tr>
    </table>
    </form> 
    </div>
    
    
        </body>

  11. #10
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    Here you go.
    Code:
    <head>
        <title>Petition</title>
        <script type="text/javascript">/* <![CDATA[ */  
        function checkBoxCheck() {
            if (!document.getElementById("check_box").checked) {
                alert("Please tick the box provided");
                return false;
            } else {
                return true;
            }
        }
    
        /* ]]> */ 
        </script> 
        </head>
        <body>
            <div align="center">
                <form method="post" action="formmail.php" onSubmit="return checkBoxCheck()">
                    <table border="0" cellpadding="10" width="500">
                        <tr><td colspan="2"><img src="eidfinal.jpg" width="500" height="107" alt="logo"></td></tr>
                        <tr><td colspan="2"><input type="hidden" name="recipient" value="jamie@nuvibes.com" /></td></tr>
                        <tr><td>Email:</td><td><input type="text" name="email" size="40"></td></tr>
                        <tr><td>Please Tick the Box:</td><td><input type="checkbox" name="checked" id="check_box"></td></tr>
                        <tr><td><input type="submit" value="Submit"></td>
                        <td><input type="reset" value="Reset"></td></tr>
                    </table>
                </form> 
            </div>
        </body>
    </html>


Page 1 of 2 1 2 LastLast

Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Search tags for this page

count how many times a button has been clicked android

,
excel how to track how many times a button is pressed
,
how many times has a button been clicked
,

how to count how man times a button is pressed java

,
how to keep track of how many times you clicked on java
,
how to keep track of pressed buttons in java
,
how to use if to track how many times a button is pressed
,
html to check how many times submit button was pressed
,
javascript how to count how many times a button has been pressed
,
visual basic how to count how many times a button is clicked
Click on a term to search for related topics.
All times are GMT -6. The time now is 06:02 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com