0

I am creating a read more button but my intention is when its clicked it should show a pop message saying successful payment received then display the rest of the paragraph. Here is my code

function myFunction() {
  var dots = document.getElementById("dots");
  var moreText = document.getElementById("more");
  var btnText = document.getElementById("myBtn");

  if (dots.style.display === "none") {
    dots.style.display = "inline";
    btnText.innerHTML = "Read more";
    moreText.style.display = "none";
  } else {
    dots.style.display = "none";
    btnText.innerHTML = "Read less";
    moreText.style.display = "inline";
  }
}
<!DOCTYPE html>
<html>

<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <style>
    #more {
      display: none;
    }
  </style>
</head>

<body>
  <h2>Read More Read Less Button</h2>
  <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus imperdiet, nulla et dictum interdum, nisi lorem egestas vitae scel<span id="dots">...</span><span id="more">erisque enim ligula venenatis dolor. Maecenas nisl est, ultrices nec congue eget, auctor vitae massa. Fusce luctus vestibulum augue ut aliquet. Nunc sagittis dictum nisi, sed ullamcorper ipsum dignissim ac. In at libero sed nunc venenatis imperdiet sed ornare turpis. Donec vitae dui eget tellus gravida venenatis. Integer fringilla congue eros non fermentum. Sed dapibus pulvinar nibh tempor porta.</span></p>
  <button onclick="myFunction()" id="myBtn">Read more</button>
</body>

</html>

Here the read more button works well but I want it to show a pop up message saying successful payment received before displaying the rest of the text.. Kindly assist on this

Umutambyi Gad
  • 4,082
  • 3
  • 18
  • 39
LivingstoneM
  • 1,088
  • 10
  • 28
  • 1
    Shouldn't be hard to find a tutorial on how to set something like this up. Also lots of scripts around you can use. SO is not a tutorial service or a free code writing service. It is expected that people do the basic research themselves and when they run into actual code issues trying to acheive their goal then show their attempts and others help fix them, not write it all for you – charlietfl Jul 11 '20 at 19:40
  • One more idea here: [Display popups](https://stackoverflow.com/questions/64802720/display-popups-with-content-specific-to-the-clicked-container/75390240#75390240) – Intacto Feb 10 '23 at 19:06

1 Answers1

1

Just add an alert

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
#more {display: none;}
</style>
</head>
<body>

<h2>Read More Read Less Button</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus imperdiet, nulla et dictum interdum, nisi lorem egestas vitae scel<span id="dots">...</span><span id="more">erisque enim ligula venenatis dolor. Maecenas nisl est, ultrices nec congue eget, auctor vitae massa. Fusce luctus vestibulum augue ut aliquet. Nunc sagittis dictum nisi, sed ullamcorper ipsum dignissim ac. In at libero sed nunc venenatis imperdiet sed ornare turpis. Donec vitae dui eget tellus gravida venenatis. Integer fringilla congue eros non fermentum. Sed dapibus pulvinar nibh tempor porta.</span></p>
<button onclick="myFunction()" id="myBtn">Read more</button>

<script>
function myFunction() {

  alert("successful payment received ");

  var dots = document.getElementById("dots");
  var moreText = document.getElementById("more");
  var btnText = document.getElementById("myBtn");

  if (dots.style.display === "none") {
    dots.style.display = "inline";
    btnText.innerHTML = "Read more"; 
    moreText.style.display = "none";
  } else {
    dots.style.display = "none";
    btnText.innerHTML = "Read less"; 
    moreText.style.display = "inline";
  }
}
</script>

</body>
</html>
DCR
  • 14,737
  • 12
  • 52
  • 115
  • This is amazing, just to ask, can the pop up appear in the middle with green colour like this ones https://www.google.com/search?q=successful+payment+popup&rlz=1C1GCEU_enKE905KE905&sxsrf=ALeKk03MylECSydQ-j22sE5ZtGdQ37OnKQ:1594536715990&tbm=isch&source=iu&ictx=1&fir=jU6wY-TazxMX5M%252Cnx0VkGUtloV4JM%252C_&vet=1&usg=AI4_-kSjdp9kdJMUrzeD8fPhAUIOuwQ96g&sa=X&ved=2ahUKEwiSrqaUkMfqAhWF2-AKHd0SBXQQ9QEwAHoECAgQHQ&biw=1280&bih=587#imgrc=jU6wY-TazxMX5M – LivingstoneM Jul 12 '20 at 06:52
  • yes but it's a little more involved. One way is to create a container holding your html for everything accept the popup you want. Create the popup as a div and set the display to none. Then in your js when the button is pressed hide the container and set the popup div display to block – DCR Jul 12 '20 at 16:34