Uncaught ReferenceError when passing values via JS

0

I'm trying to pass a string and an int in a JS so it will return me in a modal and I get this error below, could anyone help me?

Trying to pass the values here in td to JS and he has to give me this in modal. obs: using java spring to bring these values from the bank

<td><a href='#' onclick="setaDadosModal(nome, numero)" data-toggle="modal" data-target="#con-close-modal-altera"><i class="fa fa-pencil"></i></a></td>

My modal

<div id="con-close-modal-altera" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                        <h4 class="modal-title">Alterar Modalidade</h4>
                    </div>
                    <form name="alterarModalidade" action="alteraModalidades" method="post" role="form"> 
                        <div class="modal-body">
                            <div class="row">
                                <div class="col-md-12">
                                    <div class="form-group">
                                        <input required="" name="idModalidades" type="hidden" id="alteraIdModalidade" class="form-control"> 
                                        <input required="true" name="nomeModalidadeTemp" type="text" id="alteraNomeModalidadeTemp" class="form-control" id="exampleInputEmail1" placeholder="Digite a modalidade a ser alterada" maxlength="30"> 
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default waves-effect" data-dismiss="modal">Fechar</button>
                            <button type="submit" onclick="return alterarModal()" class="btn btn-warning waves-effect waves-light">Alterar</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>

My JS

function setaDadosModal(AltnomeModalidade, AltidModalidade) {
document.getElementById('alteraNomeModalidadeTemp').value = AltnomeModalidade;
document.getElementById('alteraIdModalidade').value = AltidModalidade;}

My Error

  

Modes: 258 Uncaught ReferenceError: yyyy is not defined at HTMLAnchorElement.onclick (modal: 258)

Line 258 that the error refers to

<td><a href='#' onclick="setaDadosModal(aaaa, 107)" data-toggle="modal" data-target="#con-close-modal-altera"><i class="fa fa-pencil"></i></a></td>
    
asked by anonymous 09.01.2018 / 21:22

1 answer

0

In the HTML you mentioned, which is the source of the error:

 <td><a href='#' onclick="setaDadosModal(aaaa, 107)" data-toggle="modal" data-target="#con-close-modal-altera"><i class="fa fa-pencil"></i></a></td>

Let's extract and focus on that part ( which is JavaScript ):

setaDadosModal(aaaa, 107)

Note that in the first parameter, you passed a variable, however, since this variable ( aaaa ) does not exist, the error is being thrown.

Probably, rather than passing a variable in the first parameter, you wanted to pass a > string , but for this, you should have done:

setaDadosModal('aaaa', 107) // Recomendado

Or alternatively:

var aaaa = 'aaaa'; setaDadosModal(aaaa, 107)

Then, in HTML:

 <td><a href='#' onclick="setaDadosModal('aaaa', 107)" data-toggle="modal" data-target="#con-close-modal-altera"><i class="fa fa-pencil"></i></a></td>

Or:

 <td><a href='#' onclick="var aaaa = 'aaaa'; setaDadosModal(aaaa, 107)" data-toggle="modal" data-target="#con-close-modal-altera"><i class="fa fa-pencil"></i></a></td>
    
09.01.2018 / 23:07