0
        form(role='form', action='/logout', method='POST')
          button.btn.btn-warning.btn-lg(type='submit') Log Out
          input(name='newList', type='hidden', value= locals.usr )
        p
          script(type="text/javascript").
            usr= new Usr();
            usr.setName("#{user.username}");
            var tk;
            if ('!{tasksTD}'!=''){tk = JSON.parse('!{tasksTD}'); usr.setToDo(tk);}
            if ('!{tasksD}'!=''){tk = JSON.parse('!{tasksD}'); usr.setDone(tk);}
            usr.setDone(tk);
            usr.write();

I render this jade document from the server side (express js) like res.render('home',{user:.., tasksTD:.., tasksD:...}) then I use a script to modify that data (using a few js files with enyos kinds and stuff, dont think that really matters, there i have made the definitions of kind Usr, setToDo, setDone). To the point.. Let´s say I want to return the variable usr when I submit, (make a form with value=usr or something like it) to use it on the server side.. is there any way to do it? I know it lacks sense a little bit, but I need to make it somewhat like this.

  • could stringify it and set another hidden input value. Or submit form with ajax – charlietfl Jul 16 '16 at 00:47
  • that´s actually what i was trying to do with the hidden value, but I don´t know how to declare the value, (value=locals.usr was a desesperate attempt). How would you do it? input(name='newList', type='hidden', value=???????). In order to submit the variable usr, which is declared inside the script. – Mariano Coria Jul 16 '16 at 00:57
  • the way you have it now would have to do it within the script tag after browser evaluates `new User()`. something like `document.getElementbyId('hidden-field-id').value = JSON.stringify(usr)`. – charlietfl Jul 16 '16 at 01:01
  • That worked, thanks! However, that line is excecuted right after usr.write.. Is there a way to excecute it when the submit button is pressed? Thanks a lot man. – Mariano Coria Jul 17 '16 at 00:41
  • sure...put it in a submit event listener – charlietfl Jul 17 '16 at 00:42
  • I tried an Onclick and it worked, thanks again. – Mariano Coria Jul 17 '16 at 00:48

0 Answers0