Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3323682
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:19:53+00:00 2026-05-17T23:19:53+00:00

I’m building a small experiment in php/javascript, where people have to rate the familiarity

  • 0

I’m building a small experiment in php/javascript, where people have to rate the familiarity of answers to certain word definitions. When given the definition the participant has to press space to see the answer, and has to rate it on a scale of 1 to 7. Upon clicking one of the radio buttons, the next definition is shown. This works fine in Chrome, but in Firefox, after the first definition, the form with the radio buttons keeps submitting itself: it shows up for an instance, and then proceeds to the next definition. Also, in IE nothing seems to work at all. I have no idea what is causing this behaviour. Here is the code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
<title>Experiment</title>
<link rel="stylesheet" href="style.css" type="text/css" media="screen, projection">
<script type="text/javascript" src="jquery.js"></script>


</head>
<body>
<script type="text/javascript" >
    $(document).ready(function(){
        var definitions = ['Solipsism: The philosophical position that I alone exist.',
                           'Ribosomes: The site of protein synthesis in the cell.',
                           'Microglia: Very small cells that remove waste material.'
                           ];
        var responses = [];

        var defCount = -1;

        var loadDefinition = function () {
            defCount++;

            if (defCount < definitions.length) {
                var defString = definitions[defCount];

                var definition = defString.split(': ');

                $('#sentence').text(definition[1]);
                $('#sentence').show();

            }
            else {
                // done
                $('#sentence').html('<b>The experiment is done. Thank you for participating!</b>');
                $('#sentence').show();

                saveData();
            }

        };

        var handleResponse = function () {
            // get sentence + id
            var defString = definitions[defCount];
            var definition = defString.split(': ');

            responses[responses.length] = 999;

            $('#sentence').hide();
            $('#scale').show();

            $('#answer').html('The answer was: <b>'+definition[0]+'</b><br><br>');
        };

        // capture space press
        $(document).keypress(function(e) {
            if (e.charCode == 32 || e.keyCode == 32) {
                handleResponse();
            }
            return false;
        });

        // capture likert scale response
        $('#init-form').submit(function() {
            $('#init').hide();
            loadDefinition();

            return false;
        });

        $("[name=likert]").click(function(){
            // get the value
            var fam_val = $("[name=likert]:checked").val();

            $('[name=likert]').attr('checked', false);

            $('#scale').hide();
            // load new definition
            loadDefinition();

            return false;
        });

        // some init
        $('#sentence').hide();
        $('#scale').hide();
    }); // $(document)
</script>

<div class="mainarea">
    <h1>Definition Familiarity Experiment</h1><br>
    <div id="box">
        <div id="init">
            <form id="init-form">
                <input type="submit" value="Begin Experiment" />
            </form>
        </div>
        <div id="sentence"></div>
        <div id="scale">
            <div id="answer"></div>
            <form id="scale-form">
                <table width="100%"> 
                  <tr>
                    <td></td>
                    <td align="center">1</td>
                    <td align="center">2</td>
                    <td align="center">3</td>
                    <td align="center">4</td>
                    <td align="center">5</td>
                    <td align="center">6</td>
                    <td align="center">7</td>
                    <td></td>
                  </tr>
                <tr><td align="center">totally unfamiliar</td>
                <td align="center"><input type="radio" name="likert" value="1"></td>
                <td align="center"><input type="radio" name="likert" value="2"></td>
                <td align="center"><input type="radio" name="likert" value="3"></td>
                <td align="center"><input type="radio" name="likert" value="4"></td>
                <td align="center"><input type="radio" name="likert" value="5"></td>
                <td align="center"><input type="radio" name="likert" value="6"></td>
                <td align="center"><input type="radio" name="likert" value="7"></td>
                <td align="center">knew the answer</td>
                </tr>
                </table>
            </form>
            <input id="scale-form-submit" type="submit" value="Submit">
        </div>
    </div>
</div>



</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T23:19:54+00:00Added an answer on May 17, 2026 at 11:19 pm

    In Firefox, apparently, after clicking a radio button the first time, it retains the focus.

    This means that the subsequent keypress event will be received by the radio button, thus executing its “click” event handler.

    I suggest you capture the “keyup” event instead, using the event object preventDefault() method instead of returning “false”:

    $(document).keyup(function(e) {
      if (e.which==32 ) {
        e.preventDefault();
        handleResponse();
      } 
    });
    

    By the way, you should be fine using the “which” property of the event object to determine which key was pressed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want to count how many characters a certain string has in PHP, but
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string
I have a jquery bug and I've been looking for hours now, I can't
I am reading a book about Javascript and jQuery and using one of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.