The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> why this code is not running, html error
aqeel
post Apr 12 2022, 08:53 AM
Post #1





Group: Members
Posts: 1
Joined: 12-April 22
Member No.: 28,312



<center>
<p></p>
<button class="srd" id="btn"><b>click here to get code </b></button>
<a class="button" href="" id="download"> BR260695 </a>
<script>
var downloadButton = document.getElementById("download");
var counter = 19000;
var newElement = document.createElement("p");
newElement.innerHTML = "";
var id; downloadButton.parentNode.replaceChild(newElement, downloadButton);
function startDownload() { this.style.display = 'none';
id = setInterval(function () { counter--;
if (counter < 0) {newElement.parentNode.replaceChild(downloadButton,newElement);
clearInterval(id);
}
else { newElement.innerHTML = +counter.toString() + "<b>⏱️ WAIT A Second</b>."; } }, 0); };
var clickbtn = document.getElementById("btn");
clickbtn.onclick = startDownload;
</script>
</center>
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Apr 12 2022, 10:47 AM
Post #2


.
********

Group: WDG Moderators
Posts: 9,630
Joined: 10-August 06
Member No.: 7



Works for me. What's the error?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
coothead
post Feb 8 2023, 09:59 AM
Post #3


Advanced Member
****

Group: Members
Posts: 194
Joined: 12-January 23
From: chertsey, a small town 25 miles south west of london, england
Member No.: 28,743



QUOTE(Pervive @ Feb 8 2023, 08:09 AM) *

. Pleased to see your issue as I think I have the same problem,
. I am also confused and in need of light on this same issue.

. Need help.



As @Christian J has already pointed out that the OP's posted
code works OK, can you explain...
  1. how you have the same problem
  2. what you are confused about
  3. why on earth you need help. IPB Image

coothead

User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Feb 8 2023, 07:33 PM
Post #4


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,716
Joined: 9-August 06
Member No.: 6



He/it just posts to inject his spam link later.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Jason Knight
post Feb 11 2023, 12:50 AM
Post #5


Advanced Member
****

Group: Members
Posts: 100
Joined: 25-December 22
Member No.: 28,719



CODE
<center>

What is this, 1997?

CODE
<p></p>

Hoping you deleted the content on purpose for posting on the forum and not just using this as a spacer, since that's not markup's job.

CODE
<button class="srd" id="btn"><b>click here to get code </b></button>

what form is this submitting? You didn't say type="button" and the default for <button> is type="submit"

Also what makes "click here to get some code" a proper name, personal title, or legal entity. Aka what <b> actually means? Don't just use <b> becuase you want the text bold, use it because it should be bold for grammatical reasons when not receivng "more emphasis" (<strong>'s job)

CODE
<a class="button" href="" id="download"> BR260695 </a>

If that's supposed to be a button, why isn't it a button?

CODE

  <script>
    var downloadButton = document.getElementById("download");  
    var counter = 19000;
    var newElement = document.createElement("p");
    newElement.innerHTML = "";  

You literally just created that paragraph. Thus its content is empty.

CODE

    var id;
    downloadButton.parentNode.replaceChild(newElement, downloadButton);
    function startDownload() {
            this.style.display = 'none';

Why would the function "startDownload" be an Element object? Did you meant to use Event.currentTarget?

CODE

            id = setInterval(
                function () {
                    counter--;
                    if (counter < 0) {
                        newElement.parentNode.replaceChild(downloadButton,newElement);  
                        learInterval(id);
                    else {

I think you're missing a "{" there.

CODE

            newElement.innerHTML = +counter.toString() + "<b>?? WAIT A Second</b>.";
         }
      }, 0);
    };  

Which I think that closing bracket finally cropped up here. Either way you shouldn't be generating markup with innerHTML for "bold that's CSS' job" and "plaintext". Hell if you created a textnode for the counter you wouldn't even need to touch the rest of the contents inside the interval.

CODE

    var clickbtn = document.getElementById("btn");  
    clickbtn.onclick = startDownload;  
  </script>

It's an element already on the DOM, use addEventListener not onclick.

CODE

</center>

Did I mention this isn't 1997?

The mix of 25 year out of date code and putting stuff together on single lines that shoudln't be is leading to a lot of errors. Worse, it makes it hard to figure out what it is you want this to even do.

Could you just better explain what you want this to do? Maybe one of us could then provide modern working code... instead of ... that.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 28th March 2024 - 02:53 PM