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 8883509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:49:44+00:00 2026-06-14T20:49:44+00:00

So this is my first attempt at JavaScript (learning Java atm) and I’m almost

  • 0

So this is my first attempt at JavaScript (learning Java atm) and I’m almost finished. What I want to do is: Remove readonly from my textarea at page refresh, and after some minutes set it to readonly with timer.

All the timers, getElement-parts, and readOnly-attributes seem to be working (finally).

JavaScript:

<script>
//x = Timelimit in minutes, z = Time remaining alert in minutes
function timeLimit(x,z) {
    var min = 60 * 1000;
    var limit = x * min;
    setTimeout(function(){ alert("Du har " + z + " minutter igjen på prøven.") },( limit - (z * min) ));
    setTimeout(function(){ alert(x + " minutter har gått.\nTiden er slutt.") },limit);
    setTimeout(document.getElementById('testroom').setAttribute('readOnly','readOnly'),limit);
}
</script>

Here’s the call for my function (put it below my textarea since it seemed to be the only way for getElement to find my textarea by id):

    <form method="post" action="insert.php" />
        <textarea name="content" id="testroom"></textarea><br>
        <input type="submit" value="Send inn for retting" />
    </form>

<script>
timeLimit(0.2,0.1);
document.getElementById('testroom').removeAttribute("readOnly",0);
</script>

If I move the removeAttribute above the timeLimit() (or put it inside the function), my textarea will stay readonly=true. If I put it below, it will stay readonly=false, even after 12 seconds (0.2 minutes, where the timer is supposed to happen).

Hopefully someone can clear this up for me, been searching a trying a lot of different syntax.

  • 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-06-14T20:49:45+00:00Added an answer on June 14, 2026 at 8:49 pm

    Your third setTimeout() call is not doing what you want. Instead it is executing the .setAttribute() method immediately. You should wrap it in a function to get it to execute later.

    setTimeout(function(){ alert(x + " minutter har gått.\nTiden er slutt.") },limit);
    setTimeout(function(){document.getElementById('testroom').setAttribute('readOnly','readOnly')},limit);
    

    Even better, you could combine the two, but make sure to put the setAttribute call first so the user can’t sneakily kill your JavaScript at a bad time:

    setTimeout(function(){
        document.getElementById('testroom').setAttribute('readOnly','readOnly');
        alert(x + " minutter har gått.\nTiden er slutt.");
    },limit);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hi this is my first attempt at JavaScript: the following function is used to
this is my first attempt at oo javascript: function GuiObject() { this.x = 0;
All, I'm pretty new with JavaScript and this is my first attempt with the
This is my first attempt to prototype. I want to initiate an AJAX request
This is my first attempt with JQgrid and I am confused from the documentation
This is my first attempt at responsive design, so I'm keeping it simple. I
This is my first attempt to write shorthand if statements however am befuddled by
this if my first attempt at using streaming for WCF, and I am struggling
This is my first attempt to create a GUI in MATLAB. I haven't been
this is my first attempt at a responsive design so excuse me if this

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.