user721264
user721264

Reputation: 487

Build an HTML select option list in Play

I want to do something similar in Play and Java:

<select id="birthyear" name="birthyear">
<option value="2007">2007</option>
<option value="2006">2006</option>
<option value="2005">2005</option>
<option value="2004">2004</option>
<option value="2003">2003</option>
<option value="2002">2002</option>
<option value="2001">2001</option>
<option value="2000">2000</option>
<option value="1999">1999</option>
<option value="1998">1998</option>
<option value="1997">1997</option>
<option value="1996">1996</option>
</select>

However I want to be able to give it a start year and an end year and build the select list dynamically.

I ame across this but in Scala and Play, but I'm not sure how to accomplish this in Java/Play?

UPDATE: Read the documentation as provided in the answer and also checked the sample projects that came installed with Play and used the following

<div>
     Select birth year of  
     #{select 'yob', items:2012..1900, value:5, id:'select3' /}
   </div>

Upvotes: 3

Views: 3727

Answers (2)

Selvakumar Ponnusamy
Selvakumar Ponnusamy

Reputation: 5543

Playframework has built in tag #{select} to achive this.

Please go thru the below link, It will help you,

http://www.playframework.org/documentation/1.1/tags#select

Upvotes: 7

Gelin Luo
Gelin Luo

Reputation: 14373

Did you try this ?

<select id="birthyear" name="birthyear">
#{list 2007..1996}
<option value="${_}>${_}</option>
#{/list}
</select>

Upvotes: 3

Related Questions