Monday, February 10, 2014

Re: hidden field value inside if block

On Mon, Feb 10, 2014 at 2:35 PM, Ionut Oprescu <ionut.oprescu@gobs.ro> wrote:
> 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
>

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

--
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+unsubscribe@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/CAFHbX1%2BOf6JK69wgGENXfRqfuwY--x_Me_Whe%3DJFTcnqO9Sg-g%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment