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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:39:00+00:00 2026-06-10T00:39:00+00:00

So I have a select for the grade on each subject. It’s predefined and

  • 0

So I have a select for the grade on each subject. It’s predefined and hence I don’t have to store grades as a table in the database. I have a list of qualifications and I using jstl for each like this: <c:forEach items="${qualificationdetails}" var="qd">.

For each item I am producing a select like this.

<select class="grade" title="Grade Obtained">
   <option value="1">1</option>
   <option value="2">2</option>
   <option value="3">3</option>
   <option value="A">A</option>
   <option value="B">B</option>
   <option value="C">C</option>
   <option value="D">D</option>
   <option value="E">E</option>
</select>

Is it possible to set the selected option using my variable qd ? something like

<option value="${qd.grade}" selected="selecetd">${qd.grade}</option>

This will add a duplicate option to the select. I think it would a bit “clunky” to make an array with the grades and send it accross for generating the options. Any ideas ?

  • 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-10T00:39:00+00:00Added an answer on June 10, 2026 at 12:39 am

    You could just let JSP render the selected attribute conditionally.

    <select class="grade" title="Grade Obtained">
        <option value="1" ${qd.grade == '1' ? 'selected' : ''}>1</option>
        <option value="2" ${qd.grade == '2' ? 'selected' : ''}>2</option>
        <option value="3" ${qd.grade == '3' ? 'selected' : ''}>3</option>
        <option value="A" ${qd.grade == 'A' ? 'selected' : ''}>A</option>
        <option value="B" ${qd.grade == 'B' ? 'selected' : ''}>B</option>
        <option value="C" ${qd.grade == 'C' ? 'selected' : ''}>C</option>
        <option value="D" ${qd.grade == 'D' ? 'selected' : ''}>D</option>
        <option value="E" ${qd.grade == 'E' ? 'selected' : ''}>E</option>
    </select>
    

    Alternatively, you could just create a collection/array of grades and store it in the application scope so that it’s available in EL so that you can loop over it using <c:forEach>. I’m not sure how that would be “clunky”. You could use <c:set> to store them commaseparated and use fn:split() to split them for <c:forEach>.

    <c:set var="grades" value="1,2,3,A,B,C,D,E" scope="application" />
    <select class="grade" title="Grade Obtained">
        <c:forEach items="${fn:split(grades, ',')}" var="grade">
            <option value="${grade}" ${qd.grade == grade ? 'selected' : ''}>${grade}</option>
        </c:forEach>
    </select>
    

    This way you end up with more DRY code.

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

Sidebar

Related Questions

i have a table with columns ID,SUBJECT,BRANCH i have select the rows which satisfies
I have this query: $this->set('grades', $this->Grade->Query( SELECT AVG(grade), sections.section_name FROM grades, sections WHERE sections.id
I have this table in my database: classes id | classname | grades id
I have a table with the columns, id, date, estValue & gradeid. Each grade
Let's say I have a subtable called result . SELECT school, grade FROM (SELECT
I have a simple general weighed average computation in my SELECT : SELECT ROUND(SUM((G.UnitsAcademic*GD.Grade))/SUM(G.UnitsAcademic),3)
Let's say I have SELECT name FROM table which gives me something like foo
suppose I have SELECT * FROM table t GROUP BY j HAVING condition_one OR
I have a table. In this table have select element. How can I find
I have a MYSQL table that is 1275 fields wide. Each row in the

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.