The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

> 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
 
Reply to this topicStart new topic
Replies
Jason Knight
post Feb 11 2023, 12:50 AM
Post #2


Advanced Member
****

Group: Members
Posts: 109
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

Posts in this topic
aqeel   why this code is not running   Apr 12 2022, 08:53 AM
Christian J   Works for me. What's the error?   Apr 12 2022, 10:47 AM
Jason Knight   <center> What is this, 1997? <p>...   Feb 11 2023, 12:50 AM


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: 16th May 2024 - 09:47 PM