Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8344729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:27:41+00:00 2026-06-09T06:27:41+00:00

I am currently trying to use javascript to display an extra form field if

  • 0

I am currently trying to use javascript to display an extra form field if the product selected returns true on a method which checks for this. While I have the onchange part setup for the form select I am struggling to actually get access to the products methods. I’m assuming I have to use json which I have no experience with. I’m hoping to do the following which is use the return from the method in an if statement. The code I am attempting to use at the moment is (I realise it is just displaying an alert atm but my priority is to get it working):

function openingCheck(optionValue){
    {% check_opening_date as json %}
    var checkOpeningDateJSON = {{json|safe}};

    if(checkOpeningDateJSON)
        alert(optionValue);

};

Which uses:

@register.tag(name="check_opening_date")
 def check_opening_date(parser, token): 
"""return whether the product should show the opening date or not"""

product = Product.objects.get(pk=productID)

return serializers.serialize('json',product.show_opening_date())

The issues I am having is I’m not sure how to pass optionValue to the check_opening_date function and also how to return the value of product.show_opening_date().

Any tips will be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T06:27:43+00:00Added an answer on June 9, 2026 at 6:27 am

    There are two approaches.

    1. When rendering the page, save the result of show_opening_date() somewhere along with the form select. That means that for every product listed, you either create a corresponding hidden input somewhere, or save the result as an attribute in the select or something. When a product is selected, you simply use javascript to check the value of this hidden input or attribute. No interaction with the server is required with the server after load. (There is one request to the server over all)

    2. Alternatively, you simply display the products. When one is selected, you use ajax to contact the server with an ID for the product. The server runs product.show_opening_date() and returns json with the result. (There are numerous requests to the server; the initial, and everytime a user selects a product)

    What you have doesn’t make sense. Remember that the template (along with all your template variables and template tags) are assembled when the page is rendered, so they don’t have any concept of javascript being carried out (or onchange events etc). You seem to be a bit confused by the concept of template tags. These should be used for template logic to display information that has been aggregated in the view (generally – it’s not set in stone).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently trying to create buttons which are in the form of loosely stacked
I am currently trying to use AJAX in my application via jRails. I am
I'm currently trying to use the latest stable fmod ex in my project. I
I am currently trying to use this gem http://github.com/pengwynn/linkedin . Everything works fine (i.e.
So i am running into a major issue. I am currently trying to use
I'm having trouble editing an XML file. I'm currently trying to use Nokogiri ,
Currently I am trying to use a bunch of custom perl modules, test.pm as
currently i'm trying to use imagick to generate some images without saving them on
What I am currently trying to do is use the Face API to detect
I am currently trying to research how to use Android with an existing java

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.