Matt
Matt

Reputation: 11

JavaScript Countdown - Block Text Box

I have a log out webpage on my website. I have added a JavaScript piece to my webpage so that after 5 seconds, it redirects back to my homepage. I also have a text box that counts down from 5.

What I want to do is keep the text box on my webpage and keep it counting down, the only thing is that I want to make the text box non-editable.

Below is my JavaScript script on my webpage:

<script type="text/javascript">
//<![CDATA[
      var targetURL="http://www.example.com/index.php"
      var countdownfrom=5


      var currentsecond=document.redirect.redirect2.value=countdownfrom+1
      function countredirect(){
      if (currentsecond!=1){
      currentsecond-=1
      document.redirect.redirect2.value=currentsecond
      }
      else{
      window.location=targetURL
      return
      }
      setTimeout("countredirect()",1000)
      }

      countredirect()
      //]]>
      </script>

I have that script connected to a form:

<form name="redirect">
      <center>
        <font face="arial" size="4"><strong>Please wait. You will
        be redirected in</strong></font>
          <font face="arial" size="4"><strong><input type="text"
          size="4" name="redirect2" /></strong></font>
        </form>

Upvotes: 0

Views: 193

Answers (1)

thephpdev
thephpdev

Reputation: 1117

Add the attribute disabled="disabled" to the <input /> element. This will make the input non-editable.

Your HTML should look like this:

<form name="redirect">
    <center>
        <font face="arial" size="4">
            <strong>Please wait. You will be redirected in</strong>
        </font>
        <input type="text" size="4" name="redirect2" disabled="disabled"  />
    </center>
</form>

Upvotes: 2

Related Questions