Variable JavaScript undefined

1

I'm trying to pass a value through a input type hidden of the HTML generated in PHP to JavaScript, however this variable in JavaScript is like Undefined. What can it be?

PHP

<form name='form5' method='post'>
<input type='hidden' name='id-playlist' value='$consulta[id_playlist]'>
<input type='image' id='carregar-playlist' src='images/play-circle-24.png' alt='Botao'>
</form>

JavaScript

$(document).ready(function(){
  $(document).on('click', '#carregar-playlist', function () {
    id_playlist=$("#id-playlist").val();
    alert(id_playlist);
});
    
asked by anonymous 02.11.2014 / 23:49

1 answer

4

To get the value $("#id-playlist") , you need to be in HTML as:

<input type='hidden' id="id-playlist" name='id-playlist' value='$consulta[id_playlist]'>

The id = id-playlist attribute in HTML was missing.

    
02.11.2014 / 23:58