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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:16:08+00:00 2026-06-10T06:16:08+00:00

How can you correctly pre-populate a select control with the current value from the

  • 0

How can you correctly pre-populate a select control with the current value from the template?

I have a simple form to edit a record where the values for the selected record are pre-populated when the form is shown. A bit like this:

<input type="text" id="project_name_edit" value="{{selected_name}}">

But where I am using a select control I need to be able to interogate the template value and conditionally set the selected='selected' property for the correct option.

<select id="project_status_edit" value="{{selected_status}}">
      <option>GOOD</option>
      <option>BAD</option>
      <option>UGLY</option>
</select>

handlesbars.js offers the #IF helper but this only gives truthy or falsy.

I could probably hack this in various way but this seems like a scenario where there would be a standard solution.

  • 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-10T06:16:09+00:00Added an answer on June 10, 2026 at 6:16 am

    You can use a helper:

    Handlebars.registerHelper('selected', function(foo, bar) {
      return foo == bar ? ' selected' : '';
    });
    

    Which you can then call with:

    <select id="project_status_edit">
      <option{{selected foo "GOOD"}}>GOOD</option>
      <option{{selected foo "BAD"}}>BAD</option>
      <option{{selected foo "UGLY"}}>UGLY</option>
    </select>
    

    Using:

    {"foo":"UGLY"}
    

    Try it here:

    http://tryhandlebarsjs.com/

    Although it doesn’t appear to let me save it. :(

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

Sidebar

Related Questions

How can I set my countdown correctly? I'm counting from 33,000.00 to zero. It
I have a UITextView that has a fixed width and height. I pre-populate the
I have a text area that I want to pre-populate with some specific text
I am using jQuery tokeninput to pre-populate a text area. I have an array
Can anyone tell me how I can correctly pass my application context to my
The JSON that I am parsing can be found here 'redacted'. I can correctly
Here's the troublesome function. I can not correctly locate the nested UL element: function
Not sure if I can explain this correctly, but I am trying to execute
I'm a bit worried if this function sends emails that can be recognized correctly
How can i write this correctly ? I want to check how many days

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.