2013年9月18日 星期三

html-select-template

html

<select name="employee.surname" id="employee.surname"
onchange="keyValue=this.value; retrieval();"
 >
</select>


Javascript

Add option case 1 (simple add) 

var obj_field=document.getElementById('employee.surname');
obj_field.options[0] = new Option('','');
obj_field.options[1] = new Option('new text','new value');
obj_field.options[2] = new Option('new text1','new value1');


Add option case 2 (by json)

s='tableRead?table=employee&fields=surname,employeenumber&key=status&value=0&format=S,S&callback=?'
$.getJSON(s,
function(data) {
if (data[0]){
for (r=0 ; r<data.length; r++)
{
obj_field.options[r+1] = new Option(data[r][0],data[r][1]);
} } }
)


沒有留言:

張貼留言