开发者

How to use radio buttons whose options are other html elements

How would you create radio buttons whose options are other html elements?

For instance, I need two radio buttons - the first will show a dropdown menu and the other - a simple text field.

The dropdown menu will get its options from the DB and the user will be able to choose one of these options and hit "submit".

But he could also choose to fill the text field and hit "submi开发者_开发百科t" instead.


Create a div container that will hold your text field/drop down. Add an onChange trigger to the radio that gets its value and if its value is lets say 'textbox', use appendChild to add a textbox to the container. Same for the drop down.


You should put an "onchange" event trigger on the radio tags. The javascript can be whatever you want; I would think that you would give a unique ID to the dropdown menu and text field, and toggle the CSS display property from hidden to block when the radio buttons are selected.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜