Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to call a function on submit?
    text
    copied!<p>I am not able to call jQuery on submit. The alert in the function is not displayed.</p> <p>I want to display an alert of all the checked checkbox names.</p> <p>here's my code:</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt; &lt;html&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt; &lt;title&gt;Insert title here&lt;/title&gt; &lt;/head&gt; &lt;script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"&gt; &lt;/script&gt; &lt;script&gt; $(document).ready({ $("#roleManagement").submit(function() { alert("hi"); var selected = new Array(); $('#checkboxes input:checked').each(function() { selected.push($(this).attr('name')); }); $.each(selected, function(key, value) { alert(key + ": " + value); }); }); &lt;/script&gt; &lt;body&gt; &lt;form method="post" id="roleManagement"&gt;Role Id &lt;input type="text" name="roll_id" /&gt; &lt;br&gt;Role Name &lt;input type="text" name="roll_name" /&gt; &lt;br&gt;Role Description &lt;textarea name="roll_desc"&gt;&lt;/textarea&gt; &lt;br&gt; &lt;br&gt; &lt;br&gt; &lt;div id="checkboxes"&gt;Screen1 &lt;br&gt;tab1 &lt;br&gt; &lt;input type="checkbox" name="s1_t1_view" value="s1_t1_view" checked="checked &gt;view&lt;br&gt; &lt;input type=" checkbox " name="s1_t1_add " value="s1_t1_add " &gt;add&lt;br&gt; &lt;input type="checkbox " name="s1_t1_edit " value="s1_t1_edit " &gt;edit&lt;br&gt; &lt;input type="checkbox " name="s1_t1_delete " value="s1_t1_delete " &gt;delete&lt;br&gt; tab2&lt;br&gt; &lt;input type="checkbox " name="s1_t2_view " value="s1_t2_view " &gt;view&lt;br&gt; &lt;input type="checkbox " name="s1_t2_add " value="s1_t2_add " &gt;add&lt;br&gt; &lt;input type="checkbox " name="s1_t2_edit " value="s1_t2_edit " &gt;edit&lt;br&gt; &lt;input type="checkbox " name="s1_t2_delete " value="s1_t2_delete " &gt;delete&lt;br&gt; Screen2&lt;br&gt; tab1&lt;br&gt; &lt;input type="checkbox " name="s2_t1_view " value="s2_t1_view " &gt;view&lt;br&gt; &lt;input type="checkbox " name="s2_t1_add " value="s2_t1_add " &gt;add&lt;br&gt; &lt;input type="checkbox " name="s2_t1_edit " value="s2_t1_edit " &gt;edit&lt;br&gt; &lt;input type="checkbox " name="s2_t1_delete " value="s2_t1_delete " &gt;delete&lt;br&gt; tab2&lt;br&gt; &lt;input type="checkbox " name="s2_t2_view " value="s2_t2_view " &gt;view&lt;br&gt; &lt;input type="checkbox " name="s2_t2_add " value="s2_t2_add " &gt;add&lt;br&gt; &lt;input type="checkbox " name="s2_t2_edit " value="s2_t2_edit " &gt;edit&lt;br&gt; &lt;input type="checkbox " name="s2_t2_delete " value="s2_t2_delete " &gt;delete&lt;br&gt; &lt;/div&gt; &lt;input type="submit " name="sumbit " text="submit "&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Where am I going wrong?</p>
 

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