Results 1 to 2 of 2

Thread: How to disable radio buttons after certain amount of time

  1. #1
    Join Date
    Oct 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to disable radio buttons after certain amount of time

    hi

    i have following code
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <!--<meta http-equiv="refresh" content="51;url=quiz2action.php" />-->
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Untitled Document</title>
    </head>
    
    <body>
    <div id = "time"></div>
    
    <script type = "text/javascript">
    }
    
    function display(secs) {
    if (secs <= 0) {
    alert("Your time is up!");
    return;
    }
    secs--;
    document.getElementById("time").innerHTML = "You have " +
    Math.floor(secs/60) + ":" + (secs % 60 < 10 ? "0" : "" ) + (secs % 60) + " left";
    setTimeout("display("+secs+")",1000);
    }
    
    display(51); // 300 seconds = 5 minutes
    
    </script>
    <p>
    <form name="form1" method="post" action="quiz2action.php">
      <?php
    $db = mysql_connect("localhost");
    mysql_select_db("videoshop", $db);
    
    //$queryquestions = "SELECT * FROM quiz ORDER BY RAND()" or die();
    $queryquestions = "SELECT * FROM quiz" or die(); 
    $resultquestions = mysql_query($queryquestions) or die();
    
    while($rowquestions = mysql_fetch_array($resultquestions))
    {
       $questionid = $rowquestions['id'];
       $question = $rowquestions['question'];
       $answerone = $rowquestions['option1'];
       $answertwo = $rowquestions['option2'];
       $answerthree = $rowquestions['option3'];
       $answerfour = $rowquestions['option4'];
       echo "   
        <b>Question $questionid: $question</b><br>
       <input type=\"radio\" name=\"question[$questionid]\" value=\"1\"> $answerone <br>
       <input type=\"radio\" name=\"question[$questionid]\" value=\"2\"> $answertwo <br>
       <input type=\"radio\" name=\"question[$questionid]\" value=\"3\"> $answerthree <br>
       <input type=\"radio\" name=\"question[$questionid]\" value=\"4\"> $answerfour <br>";
       
       echo "<br><br>";
    }
    
    ?>
    </p>
      <label>
      <input type="submit" name="Submit" id="button" value="Submit">
      </label>
    </form>
    <p>&nbsp;</p>
    </body>
    </html>
    above is the code of quiz which is created in php. that quiz is fine. the problem in in js script above the php script.
    what i want is when the time of 5 mins is completed then i want to disable all those radio buttons except submit button.

    how can this be done?

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Assuming that the rest of it works as expected, change:

    Code:
    if (secs <= 0) {
    alert("Your time is up!");
    return;
    }
    to:

    Code:
    if (secs <= 0) {
    var radios = document.getElementsByTagName('input'), i = radios.length - 1;
    for (i; i > -1; --i){
    if(radios[i].type === 'radio'){
    radios[i].disabled = true;
    }
    }
    alert("Your time is up!");
    return;
    }
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

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