hinata hinata - 1 year ago 115
Javascript Question

Changing button text by Click in JavaScript

I'm using following codes in a JSP page.This is my function to change button text by a button click in JavaScript.

function click(){
var el=document.getElementById(btnaccept);

This is my button;

<button type="button" class="btn btn-default btn-sm" id="btnaccept" onclick="click()">
<span class="glyphicon glyphicon-ok" aria-hidden="true" name="accept"></span> Accept

This code is not functioning when I click the "Accept" button. What error I have done here?

Answer Source

Try this code

      function click1() {
        var el = document.getElementById('btnaccept');
        if (el.textContent == "Accept") {
          el.textContent = "Accepted";
        } else {
          el.textContent = "Accept";

change onclick event to click1()

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download