开发者

rendering a list of varying length in html page

开发者 https://www.devze.com 2023-03-01 10:52 出处:网络
hi I need to render a list of objects(eg. hotels) in html page and the user should select a hotel then the hotel id should be posted back to the controller,

hi I need to render a list of objects(eg. hotels) in html page and the user should select a hotel then the hotel id should be posted back to the controller, the length of that list is not fixed let it be n, so i thought of creating n radio boxes but i realized that html doesn't support loops, and i don't know if it is possible to create forms within javascripts

note I'm using play framework in that application

an开发者_运维技巧y help Thanks in advance


This is just the basic concept of how to iterate over an object and print out html. Not perfect, not exactly what you need, but a starting point.

var hotels = ['best western','hilton','super 8'];
for( var i=0; i<hotels.length; i++ )
{
    document.write( '<input type="radio" name="hotels" id="' + i + '" />' + hotels[i] );
} // for

In action

0

精彩评论

暂无评论...
验证码 换一张
取 消