0

I'm using handlebars to dynamically generate html pages for a NodeJS project. I have an event.js and a jquery.min.js file that are both loaded.

Here's part of the HTML :

<td>
    <input id="temps_ajout_resultat" name="temps" type="text" value="{{tempsMini}}" pattern="[0-5][0-9]:[0-5][0-9]:[0-9][0-9]" title=" Format hh:mm:ss et au moins {{tempsMini}}">
</td>
<td>
    <input id="tempsMini_ajout_resultat" class="hidden" name="tempsMini" type="text" value="{{tempsMini}}">
    <input id="nbpoints" class="hidden" name="nbpoints" type="number" value="{{nbPointsSuivant}}">
    <input id="num" class="hidden" name="num" type="number" value="{{gpnum}}">
</td>
<td><button id="valider_ajout_resultat" type="button" value="Ajouter">Valider</button></td>

And part of the Javascript :

$('body').on('click', '#valider_ajout_resultat', function() {

    console.log('test');
    console.log($('body').find('#tempsMini_ajout_resultat').val());
    console.log($('body').find('#temps_ajout_resultat').val());

    validerTempsCourse($('body').find('#tempsMini_ajout_resultat').val(), $('body').find('#temps_ajout_resultat').val());});

The problem is that clicking on the "valider_ajout_resultat" button does absolutely nothing. The console says nothing either.

Anyone sees the problem?

Thanks!

Lucky-Luke87
  • 19
  • 1
  • 4

1 Answers1

-1

Can you edit the dynamically generated code?

You could put an onclick on the button and call a function:

<button onclick="myFunction()" id="valider_ajout_resultat" type="button" value="Ajouter">Valider</button>

and then in your javascript:

function myFunction() {
    console.log('test');
    console.log($('body').find('#tempsMini_ajout_resultat').val());
    console.log($('body').find('#temps_ajout_resultat').val());

    validerTempsCourse($('body').find('#tempsMini_ajout_resultat').val(), $('body').find('#temps_ajout_resultat').val());});
}

Does this work for you?

Simon
  • 2,498
  • 3
  • 34
  • 77
  • Triggering it this way does work, but I really need to make it work the way I put it here for the following functions – Lucky-Luke87 Apr 02 '18 at 18:43