0

I have a webpage with Bootstrap 3 and I tried below code to display alert box.

   <button class="btn btn-warning" onclick="warning('Are you sure ?')">Warning</button>

its working fine with this below Javascript on my web page.

window.error = function(msg) {
    var dom = '<div class="top-alert"><div class="alert alert-danger alert-dismissible fade in " role="alert"><i class="glyphicon glyphicon-exclamation-sign"></i> ' + msg + '<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button></div></div>';
    var jdom = $(dom);
    jdom.hide();
    $("#id_template").append(jdom);
    jdom.fadeIn();
    setTimeout(function() {
        jdom.fadeOut(function() {
            jdom.remove();
        });
    }, 6000);
}

For an external JavaScript file the warning() function is giving ReferenceError: warning is not defined

My external Js given below for example

// JavaScript Document

function fetch(){

    var user = $("#id_owner").val();
    var firstname = $("#id_fname").val();
    if(firstname == ""){
        warning('You must enter First Name.');
        return false;
    }

}
3
  • Can you provide warning script Commented Oct 15, 2017 at 21:34
  • i am not using any warning script and don't know how to do that. Commented Oct 15, 2017 at 21:37
  • try changing window.error to window.warning - codepen.io/nagasai/pen/GMYQGG Commented Oct 16, 2017 at 3:35

1 Answer 1

1

You must try below code directly from your external javascript.

if(firstname == ""){

    var dom = '<div id="modals" class="alert alert-danger" style="display:none;"><button data-dismiss="alert" class="close" type="button">×</button><span class="entypo-attention"></span>  <strong>Waring</strong>&nbsp;&nbsp;You must enter First Name.</div>';
    var jdom = $(dom);
    jdom.hide();
    $("id_template").append(jdom);
    jdom.fadeIn();
    setTimeout(function() {
        jdom.fadeOut(function() {
            jdom.remove();
        });
    }, 6000);
}
Sign up to request clarification or add additional context in comments.

1 Comment

Working like a charm. Thank You!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.