-1
I’m trying to get Alert to open the modal, but it’s not working.
In function I check if the field nnfe
is filled.
function TransferenciaPedido() {
if ($("nnfe").val() == undefined) {
alert("Preencha o número da NF-e corretamente.");
$('#myModalNFe').modal('show');
}
else {
}}
I’ve tried to put too return false;
but even so the modal
closeness.
I call the function in a button
within the modal:
<button type="button" class="btn btn-success" onclick="TransferenciaPedido();" data-dismiss="modal">Concluir</button>
Put the code that calls the function to get better
– Murilo Medeiros
Without the function code it is difficult to help.
– João Pedro Schmitz
I put the function. I call it on the button onclick inside the
modal
.– Mariana
The Alert shoots?
– Murilo Medeiros
@Murilomedeiros yes, it just does not return the open modal.
– Mariana
Try . modal() without the show
– Murilo Medeiros
The same thing happens, I’ve tried to create a
function
just to open, and call her, but it didn’t work either.– Mariana
Take the date-Dismiss="modal" and on the Else Voce put . modal('Hide');
– Murilo Medeiros
Mariana you are comparing Undefined with nothing, because the
val()
of $("nnfe") is not returning anything as it is not an HTML tag to be called straight as. So it is missing or a.
or a#
. You have the browser console open?– LeAndrade
@Leandrade Look at the value, it is correct the comparison, I just need the modal to be opened after the problem. only this.
– Mariana
@Murilomedeiros did it, and continues the same behavior.
– Mariana
I think I know where the problem is. Try to get the
data-dismiss
button, and close the modal onelse
via JS.– Máttheus Spoo
What error appears in the browser console? Try to take out the
data-dismiss
button too– maiconfriedel
@Máttheusspoo I tried this way, but the same problem occurs.
– Mariana
@Maikeaerosmith has already done this, and still the modal is not open. No error appears in the browser, the modal just closes.
– Mariana
also takes away the
$('#myModalNFe').modal('show');
since the modal will remain open and will only close in theelse
and tries to compare withundefined
with===
, is safer.– Máttheus Spoo
It worked. Thank you.
– Mariana
Arrange. What was happening is that you were initially displaying the modal again before you closed the html button. Then you took the data-Ismiss, but still ordered to open the modal over the modal that was still open.
– Máttheus Spoo