How to find the value of a button with JavaScript?

JavascriptWeb DevelopmentFront End Scripts

Use the value property to get the value of a button in JavaScript.


You can try to run the following code to find the value of a button −

Live Demo

<!DOCTYPE html>
      <form id="myForm">
         <button id="btn" type="button" value="my_button">My Button</button>
         var str1 = document.getElementById("btn").innerHTML;
         var str2 = document.getElementById("btn").value;

         document.write("Button text: "+str1);
         document.write("<br>Button value: "+str2);
Published on 26-Feb-2018 12:59:54