Jquery does not take input value

Asked

Viewed 46 times

2

$(document).on('click','#submit',function(){
    console.log($('#prescricao[qtd][1]').val());
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" name="prescricao" id="prescricao[qtd][1]" class="form-control input-md prescricao" autocomplete="off" placeholder="" tabindex="2"/>

<button name="Cadastrar" class="btn btn-success" id="submit">Cadastrar</button>

1 answer

6


You must escape [] inside the string because it will be interpreted as CSS selector and selectors [] means attribute selector in HTML. So with \\before each [] it’s about time.

$(document).on('click', '#submit', function() {
  console.log($('#prescricao\\[qtd\\]\\[1\\]').val());
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" name="prescricao" id="prescricao[qtd][1]" class="form-control input-md prescricao" autocomplete="off" placeholder="" tabindex="2" />

<button name="Cadastrar" class="btn btn-success" id="submit">Cadastrar</button>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.