Search code examples
jqueryalertifyjs

Alertify JS- Change button text on prompt dialog


$("#btn_submit").click(function(){
    alertify.prompt("Please enter note/remarks for this Form:", function (e, value) {
        $("#alertify-ok").val('Submit Form'); //change button text
            if (e) {
                alertify.success("Form has been submitted");
            } else {
                alertify.error("Your form is not submitted");
            }
        });

HTML for alertify prompt dialog

<button id="alertify-ok" class="alertify-button alertify-button-ok" type="submit">
    OK
</button>

The prompt appears when user clicks on submit button. Tried changing button text using below but its not working

$("#alertify-ok").val('Submit Form'); //change button text

Fiddle- where I need to change the default OK button text to something else

How could I change the button text to Submit Form instead of default OK ?


Solution

  • <button> has innerText property and does not have value. Use .text()

    $("#alertify-ok").text('Submit Form'); //change button text
    

    Use .set('labels') option to change default text.

    alertify.prompt('Please enter your comments', 'some value', 
        function(evt, value){ alertify.message('You entered: ' + value);}
    ).set('labels', {ok:'Submit', cancel:'Cancel'});
    

    Fiddle