开发者

Example need for ajax, where on selecting a radio button will dynamically produce drop down

Example need for ajax, where on selecting a radio button will dynamically pr开发者_Go百科oduce drop down


If you use or can use jQuery, this is the way I would do it:

Having this HTML:

<input type="radio" name="myradio" value="foo" />
<input type="radio" name="myradio" value="bar" />
<input type="radio" name="myradio" value="baz" />

and assuming you have a page "your_page.php" that returns the list to populate the drop down as JSON, do this:

$("input[@name='myradio']").change(function(){
    var selected_value = $("input[@name='myradio']:checked").val();
    $.getJSON("your_page.php", { value: selected_value }, populate_dropdown);
});

function populate_dropdown(items) {
    // "items" is the ajax-loaded list based on the selected radio button.
    // Clear the drop down, populate it and show it if hidden.
}


could you explain yourself a little more?

You need an example where if you click on a radio button and select is showing?

if yes you don't need ajax.

My radio: <input type="radio" name="YOUR_RADIO" onclick="document.getElementById('selectfield').style.display='';" />

<div id="selectfield" style="display:none">
<select><option>option</option></select>
</div>

good luck ...

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜