-6

I'm trying to create this script where the user can only select one option from category 1, one option from category 2, and the click submit to generate a link. What would be the best approach if I wanted this to live online and all be done client-side without the need for a server?

mplungjan
  • 169,008
  • 28
  • 173
  • 236

1 Answers1

-1

Use radio buttons

<form>
    <fieldset id="group1">
        <input type="radio" value="" name="group1">
        <input type="radio" value="" name="group1">
    </fieldset>

    <fieldset id="group2">
        <input type="radio" value="" name="group2">
        <input type="radio" value="" name="group2">
        <input type="radio" value="" name="group2">
    </fieldset>
</form>

This answer is from here Multiple radio button groups in one form

If you edit the code a bit you get (You use value1 and value2 as strings for the link)

    <form>
        <fieldset id="group1" style="float:left;">
            <input type="radio" value="" name="group1">
            <input type="radio" value="" name="group1">
        </fieldset>

        <fieldset id="group2" style="float:right;left:100px;">
            <input type="radio" value="" name="group2">
            <input type="radio" value="" name="group2">
            <input type="radio" value="" name="group2">
        </fieldset>
       <button onclick="myFunction();">Submit</button>
    </form>

<script>
function myFunction() {
value1 =document.getElementById('group1').value ;
value2 =document.getElementById('group2').value ;
}
</script>
Community
  • 1
  • 1
O.Rares
  • 1,031
  • 1
  • 16
  • 19