Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You don't need to wait for your form to post before you can check to see if they selected a radio button. You can use javascript with the <code>onsubmit</code> listener like so:</p> <pre><code>&lt;form action="modificaPriorita.php" method="post" onsubmit="return validateForm();"&gt; &lt;table&gt; &lt;tr id="format-tabelle"&gt; &lt;th&gt;&lt;/th&gt; &lt;th&gt;&lt;span class="format-celle"&gt;TITLE&lt;/span&gt;&lt;/th&gt; &lt;th&gt;&lt;span class="format-celle"&gt;TYPE&lt;/span&gt;&lt;/th&gt; &lt;/tr&gt; &lt;?php $res = GestioneSegnalazione::showSegnalazioni(); function drawTable($res) { $title = $res[0]; $idAuthor = $res[1]; $type = $res[2]; for ($i = 0; $i &lt; $num; $i++) { print "&lt;tr class='row'&gt; &lt;td align='center' valign='middle'&gt; &lt;input type='radio' name='radio' value='$title[$i],$idAuthor[$i]'/&gt; &lt;/td&gt; &lt;td align='center' valign='middle'&gt;&lt;span class='format-celle'&gt; $title[$i]&lt;/span&gt;&lt;/td&gt; &lt;td align='center' valign='middle'&gt;&lt;span class='format-celle'&gt; $type[$i]&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt;"; } } ?&gt; &lt;/table&gt; &lt;br&gt; &lt;input type="submit" name="show" value="Show" class='freshbutton-orange' id='show-submit-segnalazione'/&gt; &lt;/form&gt; &lt;script&gt; function validateForm() { var radios = document.getElementsByName('radio'); var checked = false; for (var i = 0, length = radios.length; i &lt; length; i++) { if (radios[i].checked) { checked = true; break; } } if (checked) { return true; } else { alert('Select one segnalazione to show'); return false; } } &lt;/script&gt; </code></pre> <p>So what happens in this code is right before the form gets submitted runs the <code>validateForm()</code> function we set up. In that function it checks to see if a radio button is selected. If it is then the function returns true which allows the form to post. If it doesn't find a radio button selected it does the alert window and then returns false which prevents the form from posting. I hope this helps.</p>
    singulars
    1. This table or related slice is empty.
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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