how to fill default text in the dropdown box
Hi Friends,
Actually i am getting the values of topic from ajax request and it's populating topics on load of the body. here my problem is how to add defalutl option to this select box lik "choose topic".
<select name="topic" onChange="getCategory()">
<c:forEach items="${model.topics}" var="topic">
<option value="<c:out value="${topic.topicId}" />"><c:out
value="${topic.topicName}" /></option>
thanks and regards,
Phani.k
</c:forEach>
</select>
# 1
what if you add a line after
<select name="topic" onChange="getCategory()">
<option value="Choose Topic" selected="selected"></option>
if it dosen't work, in you AJAX call back fn,
function addOptions(selectbox,text,value)
{
var optn = document.createElement("OPTION");
optn.text = text;
optn.value = value;
selectbox.options[0].add(optn);
}
call this in onLoad after you populate all the items:
addOptions(document.getElementById("mycombobox"), "Choose Topic", "Choose Topic");
skp71a at 2007-7-12 15:21:30 >

# 2
> Hi Friends,
>
> Actually i am getting the values of topic from ajax
> request and it's populating topics on load of the
> body. here my problem is how to add defalutl option
> to this select box lik "choose topic".
> <select name="topic" onChange="getCategory()">
> <c:forEach items="${model.topics}" var="topic">
> <option value="<c:out value="${topic.topicId}"
> Id}" />"><c:out
> value="${topic.topicName}" /></option>
>
> thanks and regards,
> Phani.k
> </c:forEach>
> </select>
You haven't bothered to tell us what is the topicId of the default topic "choose topic" , so I'm assuming it is 0
<select name="topic" onChange="getCategory()">
<c:forEach items="${model.topics}" var="topic">
<option value="${topic.topicId}" selected="${topic.topicId==0? 'selected' : ''}" > ${topic.topicName} </option>
</c:forEach>
</select>