how to dynamically populate a drop down box in facebook?
I have a problem here : I want to dynamically populate a drop down box based on the selection of another drop down box !
in the main drop down box, I have an onchange= some_JS_function() that gets the data from my sql server. if I want to have the whole drop down html code and put it using setInnerXHTML(), then the part of the code received fro开发者_运维问答m my server is removed in the new drop down box. apart from that everything else is ok !
i tried to just have the options come in and put them at the appropriate places. however, this is not working at all.
can anyone please help me ?
thanks
- ahsan
I believe this is what you need:
http://remysharp.com/2007/01/20/auto-populating-select-boxes-using-jquery-ajax/
Or if you want to do it with JS only:
<html>
<head>
<title></title>
</head>
<body>
<script type="text/javascript">
<!--
function ReplaceContentInContainer(id) {
var content;
switch(id)
{
case "1":
content = '<option>4</option><option>5</option><option>6</option>';
break;
case "2":
content = '<option>7</option><option>8</option><option>9</option>';
break;
case "3":
content = '<option>10</option><option>11</option><option>12</option>';
break;
default:
content = '<option>1</option><option>2</option><option>3</option>';
}
document.getElementById("second").innerHTML = content;
}
//-->
</script>
<select name="test" id="test" onChange="ReplaceContentInContainer(this.options[this.selectedIndex].value)">
<option>1</option>
<option>2</option>
<option>3</option>
</select>
<select name="second" id="second"></select>
</body>
</html>
I believe this is what I need : FBJS...OnClick not being passed. DHTML/setInnerXHtml problem
thanks for helping :)
精彩评论