Reputation: 3511
I'm currently working on a ftl page, and I need your help. I do have a list of users, that is displayed in a dropdown menu with no selected option. Beside this list there is an href "select current user", What I need to do is to change option to choose current user to be selected in the list. here is the code:
<select class="select" name="users" id="users">
<#list users as user>
<option value="${user.id}">${user.firstName}</option>
</#list>
</select>
<a href="#">select current user</a>
BTW I do have currentUser.id. Anyone know how to achieve this using JS & YUI? Thanks in advance:)
Upvotes: 0
Views: 827
Reputation: 178026
You mean
<a href="#"
onclick="document.getElementById('users').value='$(currentUser.id}';
return false">select current user</a>
which will work in newer browsers
Older (and newer) browser might want
<script type="text/javascript">
function selectUser(val) {
var users = document.forms[0].users;
for (var i=0;i<users.length;i++) {
if (users[i].text === val) {
users[i].selected=true;
break
}
}
return false
}
</script>
<a href="#" id="${currentUser.id}"
onclick="return selectUser(this.id)" >select current user</a>
Upvotes: 2