hidden field value inside if block

20 views
Skip to first unread message

Ionut Oprescu

unread,
Feb 10, 2014, 9:35:27 AM2/10/14
to django...@googlegroups.com
is there a way to verify a hidden field value inside a if statement?

for example:

<input type="hidden" id="hdnDetails"/>
{% if details.id_details == hdnIdDetalii.value %}
  code here
{% endif %}

something like this...

note! i`m using python with google app engine, details is send from a .py file.
         the value of the hidden field is set in a javascript function when i click a button.
        
if i try to do this (the code above) i get the following error:
UndefinedError: 'hdnDetails' is undefined

Tom Evans

unread,
Feb 10, 2014, 10:02:15 AM2/10/14
to django...@googlegroups.com
No. You need to understand the order things happen in:

Python renders your HTML
The web server delivers your HTML to a client browser
The web browser runs the javascript in your HTML and updates the DOM

You are asking "How do I look at a value from the DOM before the DOM
exists". You can't. Work out a better way of doing what you are trying
to do, eg:

by using javascript to determine whether 'code here' is visible or not

by working out what the value of the node would be in python before
rendering it.

Impossible things are not possible, no matter how nice the framework.

Cheers

Tom
Reply all
Reply to author
Forward
0 new messages