mardi 17 mars 2020

How do I develop a checkbox form using JavaScript and HTML?

I am currently developing an order form with JavaScript and HTML and need to have a radio box checked for a "build your own" option. Following that, I need to have 6 checkboxes with options of different fruits to choose from. Would I use the switch statement for the checkboxes? This is what I have so far:

JavaScript:

for (var i = 0; i < document.forms[0].optBuildown.length; i++){
    if (document.forms[0].optBuildown[i].checked){
        buildOwn = i;
    }
}

switch(buildOwn){
    case 0:
      strPC = strPC + "<br><br>Build your own";
      break;

}

HTML

<td valign="top">Build your own:</td>
                <td valign="top" nowrap="nowrap">
                    <input type="radio" name="chkOption" value="opt1" onclick="return changeOption()" /> <br />
                    <input type="checkbox" name="chkOption" value="1" onclick="return orderSummary()" />Blueberry
                    <input type="checkbox" name="chkOption" value="2" onclick="return orderSummary()" />Strawberry
                    <input type="checkbox" name="chkOption" value="3" onclick="return orderSummary()" />
                    Banana
        </td>

I am a beginner coder (as you can see lol) if you can help in any way it would be greatly appreciated.




Aucun commentaire:

Enregistrer un commentaire