Does the browser support getElementById? old browsers don't support it.. If not the your aren't really adding the input tag in the same page where you run the js script. The js by it self is valid (if an element with this id exists, and only one of course)..
On Tuesday, March 17, 2015 at 5:47:03 PM UTC+2, elcaiaimar wrote: > > Hello > > I wonder if somebody knows how to solve the next: > > I want to send a value from the template to a script and it seems it works > but I get an error: Uncaught TypeError: Cannot read property 'value' of null > > Below it is my code: > > *Template:* > > <input type="hidden" id="idobra" name="variable" value="{{ obra.id }}"> > > {{ obra.id }} is an object sended from views.py > > *Javascript:* > > var idobra = document.getElementById("idobra").value; > console.log(idobra); > > And I don't know what I'm doing wrong. I would like to know if there is > another way to send objects directly from django to javascript or if I'm > doing well like that, but solving the problem. > > Thank you very much! > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/cf463ac8-9fe7-4b1d-8f48-b51b39efe5c0%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.