0

the following part of code is from a pop-up alert window, in the example page on how to use there is a button that says "Error", and when you click it the window appears.

<button class="btn btn-danger notification" data-verti-pos="bottom" data-horiz- pos="right" data-message="<i class='fa fa-frown-o' style='padding-right:6px'></i> Oops... Something went wrong. Hope we don\'t see me again." data-type="error" type="button"></button>

The problem is that i want to call the window without needing to click the button, i am trying to call it inside this if conditional.

if(codigo=="matricula_longitud"){
        //I know the part of code below is totally wrong
        document.getElementById("errores").innerHTML='<div class="alert alert-warning fade in"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button><strong>Warning!</strong> Better check yourself, youre not looking too good.</div>';
    return "si";
}

I am new to programming so any advice will be appreciated. Thank you.

Marcos
  • 63
  • 5

2 Answers2

1

You can wrap the content in a function, which is called from the event handler of your button and other function where you're showing the window without the requirement to click on a button.

var showWindow = function() {
    alert("La matricula es muy corta")
    //I know the part of code below is totally wrong
    document.getElementById("errores").innerHTML='...';
    return "si";
};

And then in your button handler

if(codigo=="matricula_longitud"){ 
    return showWindow();
}

And in your other function, just call showWindow() if you want to show it to the user.

A little remark though, if you want to check a condition, it's best to use strict equality checks, === or !== instead of == or !=. Please refer to this question for further explanation.

Community
  • 1
  • 1
KarelG
  • 5,176
  • 4
  • 33
  • 49
0

At least, you can use jquery

<button id="myBtn" class="btn btn-danger notification" data-verti-pos="bottom" data-horiz- pos="right" data-message="<i class='fa fa-frown-o' style='padding-right:6px'></i> Oops... Something went wrong. Hope we don\'t see me again." data-type="error" type="button"></button>

$('#myBtn').click();
Jiang Nan
  • 52
  • 2