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

  • SEARCH
  • Home
  • 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 8311019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:40:15+00:00 2026-06-08T19:40:15+00:00

I have a program that takes a users input in a form and assigns

  • 0

I have a program that takes a users input in a form and assigns the user input to a variable session.dataQuery to be used through the program. session.dataQuery is passed to the next function resultsDisplay() where it is processed and used to generate a set of results. In the corresponding view resultsDisplay.html, the users results are displayed along with some alternative suggestions.

I want the alternative suggestions to be clickable links that will call the resultsDisplay function and change session.dataQuery to the clicked value, generating new results based on the revised query. I have no idea how to change the variable this way. Would really love some help with this. Hope the question makes sense, if you need clarification I will be happy to do so.

def index():
    #This function gets session.dataQuery

def resultsDisplay():
    #This function uses the value assigned to session.dataQuery to
    #generate a set of results

resultsDisplay.html:
    <!-- Displays results obtained from resultsDisplay() -->
    <ul>
        <li>result_1</li>
        <li>result_2</li>
        ...
    </ul>
    <!-- Alternative suggestions here. To be clickable links to reload this page. The 
     value be sent to resultsDisplay() to become the new session.dataQuery variable and 
     be reprocessed -->
  • 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-08T19:40:18+00:00Added an answer on June 8, 2026 at 7:40 pm

    So it sounds like clicking on the link will reload the page as if the user had filled out the form differently.

    Maybe you should have the links point to resultsDisplay with some GET variables, include one that tells ‘resultsDisplay’ what new value dataQuery should get and another one that tells it not to try to process the form, but rather just overwrite the dataQuery and render the page.

    Something like

    <!-- Alternative suggestions -->
    {{ =A(alt_sugg, _href=URL(vars={'suggest':True, 'dataquery':new_query_value}) ) }}
    

    EDIT:

    what exactly is that code there? My code at the minute is:

    {{for suggestion in suggestions:}} 
      <ul><li>
        <a href="resultsDisplay.html" onclick="session.vars={{=suggestion}}>
          {{=suggestion}}
        </a></li></ul>
    {{pass}}
    

    So in ‘onclick’ you have session.vars=… is session a javascript variable? If not, what you’re doing will not work. By the time web2py is rendering the view, you should not be altering web2py’s session variable. It should be done in a controller (resultsDisplay).

    You could do this (note in the text you typed, your missing a closing quote after {{=suggestion}}):

    {{for suggestion in suggestions:}} 
      <ul><li>
        <a href="resultsDisplay.html?suggest=True&suggestion={{=suggestion}}">
          {{=suggestion}}
        </a></li></ul>
    {{pass}}
    

    You don’t need to add onclick events to <a> tags since they already respond to clicks. By adding the suggestion to the URL, you can set the session variable if you like, or use the get variable (request.vars.suggestion) directly.

    Does that make sense?

    fyi, my initial code just spits out essentially the same as what I just suggested.

    This:

    {{=A(suggestion, _href=URL(vars=dict(suggest=True, suggestion=suggestion))) }}
    

    Produces the same markup (essentially) as this:

    <a href="resultsDisplay.html?suggest=True&suggestion={{=suggestion}}">
          {{=suggestion}}
    </a>
    

    EDIT:

    So the code I have provided is only the view. One a ‘suggestion’ is clicked, the resultsDisplay() will execute again. That is where you set session.dataQuery:

    def resultsDisplay():
      if request.vars.suggest == True:
        session.dataQuery = request.vars.suggestion
    
      else:
        #This BRANCH of the function uses the value assigned to session.dataQuery to
        #generate a set of results. 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a C++ program that takes user input for fopen in order to
I have created a program that takes a users input of a bunch of
So I have a program that takes in the user credentials via Windows form,
I have a perl program that takes input and output file arguments, and I'd
Currently I have a program that takes as input a folder that contains .MPP
I am making a program that takes input from files that I have called
Question cribbed from here : I have a program that takes input from stdin
I have a query that takes input from the end user and compares it
I'm writing a tiny program that takes user input using Getops, and based on
I have a Ruby program that takes as input an HTML document. The structure

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.