> For the complete documentation index, see [llms.txt](https://support.emarketeer.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://support.emarketeer.com/docs/docs_se/guider/guides/legacy/max-answers-form-checkbox.md).

# Max antal svar för en kryssruta

Avancerad guide för att begränsa antalet valbara alternativ i en checkbox-fråga i ett formulär med ett anpassat JavaScript-kodavsnitt.

{% hint style="warning" %}
Den här artikeln gäller **Formulär (Legacy)**. För den nuvarande formuläreditorn, se [Formulär](/docs/docs_se/guider/guides/forms.md).
{% endhint %}

Den här avancerade guiden visar hur du begränsar hur många alternativ en respondent kan välja för en checkbox-fråga i ett formulär.

För att sätta gränsen lägger du till ett skript i HTML Head-sektionen för formuläret, som hittas under Edit Fonts & Colors-alternativen.

Exemplet nedan täcker två checkbox-frågor. Frågan query\_2004686 tillåter upp till 3 valda svar, och frågan query\_2005423 tillåter upp till 2.

```html
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
var jq = $.noConflict();

jq(document).on('change', 'input[name^="query_2004686"]', function (e) {
    if (jq('input[name^="query_2004686"]:checked').length > 3) {
        jq(this).prop('checked', false);
        alert("Only 3 Checked Answers Allowed");
    }
});

jq(document).on('change', 'input[name^="query_2005423"]', function (e) {
    if (jq('input[name^="query_2005423"]:checked').length > 2) {
        jq(this).prop('checked', false);
        alert("Only 2 Checked Answers Allowed");
    }
});

</script>
```

## Steg för steg

1. Kopiera koden ovan och justera den så att det finns ett `jq(document).on('change')`-block per fråga som du vill begränsa. Exemplet täcker två frågor.
2. Öppna formulärets Publish-sida och Website Integration-kodsidan så att du kan se de fråge-Names som används i koden.
3. Hämta Name-selektorn för varje checkbox-fråga från integrationskoden (till exempel "query\_2004686" från "query\_2004686\_2\_0\_0\[]"). Ersätt namnen i exemplet så att varje block använder rätt namn.
4. Ändra length-numret i varje block till det maximala antal val som är tillåtna för den frågan. Uppdatera alert-texten för samma fråga så att den speglar det nya antalet.
5. Lägg till koden i HTML Head-sektionen i formuläret under Edit Fonts & Colors-alternativen.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://support.emarketeer.com/docs/docs_se/guider/guides/legacy/max-answers-form-checkbox.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
