Javascript variable Undefined

Asked

Viewed 114 times

1

I’m trying to pass a figure through a input type hidden HTML generated in PHP for Javascript, but this variable in Javascript is undefined. What can 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);
});

1 answer

4


To get the value $("#id-playlist"), it is necessary that HTML is as:

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

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

  • On the fly! Thanks!

Browser other questions tagged

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