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 8969283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:34:14+00:00 2026-06-15T17:34:14+00:00

Not sure if I phrased this question correctly. I have a form to edit

  • 0

Not sure if I phrased this question correctly.
I have a form to edit documents from MongoDB (using Tornado templating). When they click Edit, they go to a page where the form is pre-populated. In the form I have:

{% for group in doc.groups %}
     <div class="groupMenu">
         <select name="gName0" id="groupDropDown">
              <option value="group1">Group 1</option>
              <option value="group2">Group 2</option>
              <option value="group3">Group 3</option>
         </select>
     </div>
{% end %}

I’m not very good with jQuery and wanted to ask how do you write a function so that when a person clicks on edit and goes to fill out the form, the drop down defaults are set to whatever group is for each drop down?

Hope I was able to explain myself correctly.

EDIT: I want selected=”selected” to be on group1, group2, OR group3, depending on what the group is.

  • 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-15T17:34:15+00:00Added an answer on June 15, 2026 at 5:34 pm

    Using the {% if condition %}{% end %} template tags, you could do this:

    {% for group in doc.groups %}
         <div class="groupMenu">
             <select name="gName0" id="groupDropDown">
                  <option {% if group == 'group1' %}selected="selected"{% end %} value="group1">
                      Group 1
                  </option>
                  <option {% if group == 'group2' %}selected="selected"{% end %} value="group2">
                      Group 2
                  </option>
                  <option {% if group == 'group3' %}selected="selected"{% end %} value="group3">
                      Group 3
                  </option>
             </select>
         </div>
    {% end %}
    

    If you wanted to use jQuery to do this, you could put the value in a hidden input field:

    <input class="default_group" type="hidden" value="{% group %}" />
    

    And then you could grab that value in jQuery, and set the selected option:

    var group = $('input.default_group').val();
    $('option[value="'+ group +'"]').attr('selected', 'selected');​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​
    

    Here’s the jsfiddle demonstrating this.

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

Sidebar

Related Questions

(Not really sure if I phrased the question correctly...) I want to create a
Not sure how to phrase this question, but here is the problem. I have
I'm not sure I've phrased the question correctly, so I'll try a longer explanation.
First, this question may have been asked before, but I'm not sure what phrase
I'm not quite sure how to phrase this question correctly, so I'll start with
I am not sure how to phrase this question correctly, but this is what
I am not sure if I phrased the question in the title correctly but
I'm not even sure how I should phrase this question. I'm passing some CustomStruct
I'm not sure if I phrased my question as well as I liked to
Not sure how to ask this, but i'll give it a try: I have

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.