Most efficient coding style for forms with multiple radio buttons

怎甘沉沦 提交于 2020-01-07 05:40:11

问题


I am have a form that look something like this:

I want the input.variable I am going to throw into localStorage based on the number of boxes filled out and the radio boxes checked. It would apply as follows:

-Radio Buttons-
One Name Typed in:
na : Name
F: Name and friend
F+ Name and friends

Two Names typed in:
na: Name and Name
F: Name, Name and friend
F+: Name, Name and friends

Three Names typed in:
na: Name, Name and Name
F: Name, Name Name and friend
F+: Name, Name, Name and friends

Four Names typed in:
na: Name, Name, Name and Name
F: Name, Name, Name, Name and friend
F+: Name, Name, Name, Name and friends

What would be the best way to approach this? I am trying to think of the most efficient way to write this beyond multiple if/then/else statements.

Thanks


回答1:


Ok, since my comment seems to have pointed you in the right direction, I'm pasting it here as an answer:

if you want a clean way to arrange data, use an object literal. If you're dealing with a wash of if elseif elseif statements, consider using a switch, if all conditionals check a different value, just use switch (true)



来源:https://stackoverflow.com/questions/13662166/most-efficient-coding-style-for-forms-with-multiple-radio-buttons

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!