Note that there are some explanatory texts on larger screens.

plurals
  1. POValidate Checkbox that has an array as name parameter
    primarykey
    data
    text
    <p>I used to validate checkbox form with a code like this:</p> <pre><code>&lt;div&gt; &lt;form action="survey.php" method="post" name="survey"&gt; &lt;span class="form"&gt;&lt;input type="checkbox" name="event1" onClick="return countMarketing()"&gt;Event1&lt;/span&gt; &lt;span class"form"&gt;&lt;input type="checkbox" name="event2" onClick="return countMarketing()"&gt;Event2&lt;/span&gt; &lt;span class"form"&gt;&lt;input type="checkbox" name="event3" onClick="return countMarketing()"&gt;Event2&lt;/span&gt; &lt;!-- other forms --&gt; &lt;/form&gt; &lt;/div&gt; </code></pre> <p>And a javascript validation that is something like this (to limit the count of checkboxes checked):</p> <pre><code>function countMarketing() { var NewCountMarketing = 0 if (document.survey.event1.checked) {NewCountMarketing = NewCountMarketing + 1} if (document.survey.event2.checked) {NewCountMarketing = NewCountMarketing + 1} if (document.survey.event3.checked) {NewCountMarketing = NewCountMarketing + 1} if (NewCountMarketing == 3) { alert('Please choose only two') document.survey; return false; } } </code></pre> <p>And validation like this works. But now, say im using php to for the submission, how do i check if in JS if the name of the form is something like this:</p> <pre><code> &lt;input type="checkbox" name="events[]" id="event1" onClick="return countMarketing()"&gt;Event1 </code></pre> <p>Ive tried to change the JS to:</p> <pre><code>if (document.survey.events[].checked) {code here} if (document.survey.getElementByName('events[]').checked) {code here} if (document.survey.getElementById('event1').checked) {code here} </code></pre> <p>But it doesnt work.. any can shed some light on me about this? thank you very much :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload