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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:30:09+00:00 2026-06-05T07:30:09+00:00

I have a menu that I want to differ based on which account is

  • 0

I have a menu that I want to differ based on which account is currently selected in the system.

I have a page that allows a user to select an account from an html select. When the user submits the form from the account selection page I want to call the menu method on my controller passing in the selected value so my url looks correct.

Here is the existing template from the page that allows a user to select an account:

@helper.form(action = routes.Accounts.menu {
    <table>
        <tr>
            <td><select id="accountNames">
                @accountNames.map { name =>
                    <option value="@name">@name</option>
                }
            </select></td>
        </tr>
        <tr>
            <td>
                <p>
                    <input type="submit" value="Choose">
                </p>
            </td>
        </tr>
    </table>
}

From my routes file:

GET /account/:accountName/menu controllers.Accounts.menu(accountName: String)

How do I reference the selected value from my select (id=”accountNames”) and pass it into my form action?

  • 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-05T07:30:10+00:00Added an answer on June 5, 2026 at 7:30 am

    Actually I think you’re on the wrong side for doing that.

    If the form’s action has to change over the use of your ‘select’, it has to be done using JS.
    So when the form is submitted (event submit) you have to update the url.

    This can be done easily using javascriptRoutes.

    So you have to do several things:

    1/ create the javascriptRouter (assuming your add it in Application.scala)

    def javascriptRoutes = Action {
      Ok(
        Routes.javascriptRouter("playRoutes")(
          //accounts
          controllers.routes.javascript.Accounts.menu
        )
      ).as("text/javascript")
     }
    

    2/ define it in your routes file

    # Javascript routing
    GET     /assets/javascripts/routes      controllers.Application.javascriptRoutes
    

    3/ add the related javascript file import in your views, let say in main.scala.html

    <script type="text/javascript" src="@routes.Application.javascriptRoutes"></script>
    

    4/ add a submit handler to your form that does that before executing the default behavior

    $("form").submit(function () {
        //this computes the correct URL giving a parameter which is the value of the selected option
        var newURl = playRoutes.controllers.Accounts.menu($("#accountNames").val()).url
        $(this).attr("action", newUrl); 
    })
    

    Notice how we’ve used playRoutes both in the controller (1) and the JS call (4).

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

Sidebar

Related Questions

I want to have a menu display that accepts user input. However, I want
I have a menu item that I want to show/hide only if the user
I have a menu system that I want to initialise from constant data. A
Basically, I have drop down menu that looks like this: <select> <option>0</option> <option selected=selected>1</option>
So I have a menu that I want to generate a main menu based
I have a menu that let's a user select a country. Exactly like that
I have a menu and label in my master page which i want to
I have a menu that changes and I want to show content in the
I want that the menu i have created for testing entries should come in
I have a CSS dropdown menu that is functioning how I want it to

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.