I want to clear the check box and text box that reside on my form by the click of the button. I was able to clear the Text boxes, but check box is not clearing up. Below is my entire code.   Code to clear the check boxes and Text boxes:  &lt;script src="Scripts/jquery-3.1.0.min.js" type="text/javascript"&gt;&lt;/script&gt;  &lt;script type="text/javascript"&gt;     $(document).ready(function () {         $("#btnReset").click(function () {              $("input[type=checkbox]").removeAttr('checked');             $("input[type=text]").val("");             $("textarea").val("");          });     });     I also tried putting   $('.chkPool').each(function () { this.checked = false; });   instead of   $("input[type=checkbox]").removeAttr('checked');   both the above lines does not work.  The reset button that is clicked to clear text boxes and checkboxes:  &lt;input type="button" id="btnReset" value="Clear Fields" /&gt;   The check box that I am trying to clear, but is not working is below:   &lt;asp:CheckBox ID="chkPool" runat="server" Text="Pool" /&gt;   any help will be appreciated.
3314
I'd like to do something like this to tick a checkbox using jQuery:  $(".myCheckBox").checked(true);   or  $(".myCheckBox").selected(true);   Does such a thing exist?
50605
How do I save user-entered line breaks from a &lt;textarea&gt; HTML element to a database?  It always removes the line breaks.
60861
I have an AJAX button that should update form fields according to data already provided by user:   'ajax_button' =&gt; array(     '#type' =&gt; 'button',     '#value' =&gt; t("Scan for tags"),     '#ajax' =&gt; array(       'callback' =&gt; 'ajax_tag',       'wrapper' =&gt; 'dynamic-tags-fieldset',       'method' =&gt; 'replace',       'event' =&gt; 'click',       'prevent' =&gt; 'submit click mousedown',     ),   ),   It works, but only if form is valid. Of course I do not want to validate it just yet. I don't care if all fields are filled, I only need my form to be updated at this very moment. How can I make form api not to invoke hook_form_validate() and not test #required fields?
9151
How can I check the existence of an element in jQuery?  The current code that I have is this:  if ($(selector).length &gt; 0) {     // Do something }   Is there a more elegant way to approach this? Perhaps a plugin or a function?
106015
I'm using  to modify the content of the form on the search page &mdash; I want to remove the "phrase" and "not" fields, and restrict the "only of the types" checkboxes to a hand selected list of types.  I have the following code, which is being called and which I think should work:  function MYMODULE_form_search_form_alter(&amp;$form, &amp;$form_state, $form_id) {     unset($form['basic']);     unset($form['advanced']['keywords']['phrase']);     unset($form['advanced']['keywords']['negative']);     unset($form['advanced']['type']);     $form['advanced']['type'] = array(         '#type' =&gt; 'checkboxes',         '#title' =&gt; t('Only of the type(s)'),         '#options' =&gt; array(             'blog' =&gt; 'Blog entry',             'event' =&gt; 'Event',             'news' =&gt; 'News article'         )     );     // print_r($form);     // die; }   Except  gets to the search form after my form alter hook runs, so I don't get a chance to modify any of the form elements that it's adding.  I'm running Drupal 7.22.  How can I modify the advanced search form when my module hook runs before the hook that defines the advanced search form?
11336
How do you create a simple, custom rule using the jQuery Validate plugin (using ) that doesn't use a regex?  For example, what function would create a rule that validates only if at least one of a group of checkboxes is checked?
112
I have a bit of code where I am looping through all the select boxes on a page and binding a .hover event to them to do a bit of twiddling with their width on mouse on/off.  This happens on page ready and works just fine.  The problem I have is that any select boxes I add via Ajax or DOM after the initial loop won't have the event bound.  I have found this plugin (), but before I add another 5k to my pages with a plugin, I want to see if anyone knows a way to do this, either with jQuery directly or by another option.
108897
I have created a checkbox in user edit using form alter and based checkbox state I want to print the message. For this I used below code  function module_form_user_profile_form_alter(&amp;$form, &amp;$form_state) {    $form['account']['checkbox'] = array(     '#type' =&gt; 'checkbox',     '#title' =&gt; 'Test check',    );    $form['#submit'][] = 'module_simplenews_unsubscribe'; }  //~ //Submit handler for Subscribe/unsubscribe newsletter. function module_simplenews_unsubscribe($form, &amp;$form_state) {    if ($form['account']['checkbox']['#value'] == 0) {     drupal_set_message(t("You are checked"));   }  if ($form['account']['checkbox']['#value'] == 1) {      drupal_set_message(t("You are unchecked"));   } }   It works fine. When checkbox is checked/unchecked and user saves the profile it prints respective message. But when user doesn't modify this checkbox field and modify some other field and saves, again it prints message based on checkbox state.  I want to display the message only when checkbox field is modified. How can I achieve this?
31007
Help!!!  I don't know quite what happened, I was getting frustrated, trying to somehow escape the backticks inside the code formatting. I clicked the edit button too many times, and then the above happened. Perhaps I clicked it to fast, I don't know, but I then got lots of boxes.    Edit:  Based on a test case below, the problem is simply caused by pressing edit while you still have an edit box open. They all go away when you press cancel anywhere once. This makes it much easier to reproduce, and, while not very important, perhaps still something to be fixed.  Note on the pattern:  When you click the first time, you get one box, as normal. When you click again, you get one extra empty box at the top, and another normal box above that. At each click, one empty box is added per existing normal boxes, plus one normal box. What is going on?
9942
Is there an easy way to delete an element from an array using PHP, such that foreach ($array) no longer includes that element?  I thought that setting it to null would do it, but apparently it does not work.
83075
I want to be able to close an alert box automatically using Javascript after a certain amount of time or on a specific event (i.e. onkeypress).  From my research, it doesn't look like that's possible with the built-in alert() function.  Is there a way to override it and have control over the dialog box that it opens?  Also, I don't want an override that shows a hidden div as the alert.  I need an actual dialog box.
37853
Is there a function like document.getElementById("FirstDiv").clear()?
96070
I am facing problem in marking checkbox true. Below is my cases  Case1:(It is correct and working)  I need records which have duplicate names and do not have any opportunity or contact associated with them. If the names are same and they have any of the Opportunities or the contacts linked then mark them as duplicates. E.g; if there are 2 such records then mark any 1 of them as  duplicate.  Case 2:(Wrong result)  Suppose, there are a total of 3 duplicate records(with the same names) out of which 1 record is having either opportunity or contact or even both associated with it and remaining 2 do not have any such relationship, then these should be marked as duplicate.  But, in my case it is marking one checkbox(duplicate__c) as true  List&lt;Account&gt; actLst = new List&lt;Account&gt;(); Set&lt;String&gt; userNames = new Set&lt;String&gt;();  List&lt;Account&gt; accList = [SELECT Name,Id  , Prospect_Code__c  , duplicate__C  FROM Account where Id Not                            In (Select AccountId from Contact) And Id Not In (Select AccountId from Opportunity)];                           for(Account account_i : accList) {      if(!userNames.contains(account_i.Name)) {         userNames.add(account_i.Name);      } else {         account_i.duplicate__c = true;         actLst.add(account_i);     }     system.debug('actLst &gt;&gt; ' + actLst);     update actLst;  }
123115
What's the best way to get a regular anchor (&lt;a href="..."&gt;) to submit the form it is embedded in when clicked?  &lt;form&gt;     &lt;ul&gt;         &lt;li&gt;             &lt;p&gt;                 The link could be &lt;span&gt;embedded &lt;a href="" onclick="?"&gt;at any level&lt;/a&gt;&lt;/span&gt;                 in the form, so "this.parentNode.parentNode..." is no good. :(             &lt;/p&gt;         &lt;/li&gt;     &lt;/ul&gt; &lt;/form&gt;   I know that the easiest way using jQuery would be  $('#myLink').click(function() {     $(this).parents('form:first').submit(); });   ...but I'm trying to find a way to do this without using a library.    Edit: I'm really trying to find a method which doesn't require knowledge of the form (eg: its name, id, etc). This would be similar to how you could put this on an input element: &lt;input onclick="this.form.submit()" /&gt;
32885
I have some html like this:  &lt;div id="1"&gt;     &lt;p&gt;         Volume = &lt;input type="text" /&gt;         &lt;button rel="3.93e-6" class="1" type="button"&gt;Check answer&lt;/button&gt;     &lt;/p&gt;     &lt;div&gt;&lt;/div&gt; &lt;/div&gt;   and some JS like this:  $("button").click(function () {     var buttonNo = $(this).attr('class');     var correct = Number($(this).attr('rel'));      validate (Number($("#"+buttonNo+" input").val()),correct);     $("#"+buttonNo+" div").html(feedback); });   What I'd really like is if I didn't have to have the class="1" on the button (I know numeric classes aren't valid, but this is a WIP!), so I could determine buttonNo based on the id of the parent div. In real life there are multiple sections looking like this.   How do I find the id of the div parenting the button. What would be a more semantic way to store the answer in the button code. I want to make this as foolproof as possible for a non programmer to copy and paste without breaking things!
92276
I have a form that is dynamically generated, and has dynamically generated id's (and potentially classes). The forms are the same but they have the related id tacked on to the end.  How can I select each set of inputs and apply code to each one?  I was experimenting with $('input[id^=@id_airline_for_]') but could not get it to fly. I suspect I am missing some fundamental jQuery knowledge that is holding me back since I am sure this is a common problem with dynamic forms.   &lt;form method='POST'&gt;     &lt;label for="id_airline_for_8"&gt;Airline&lt;/label&gt;:     &lt;input id="id_airline_for_8" class="arrival_transfer_toggle_8" type="text" maxlength="30" name="airline_for_8"/&gt;     &lt;label for="id_flight_number_for_8"&gt;Flight Number&lt;/label&gt;:     &lt;input id="id_flight_number_for_8" class="arrival_transfer_toggle_8" type="text" maxlength="30" name="flight_number_for_8"/&gt;      &lt;label for="id_airline_for_17"&gt;Airline&lt;/label&gt;:     &lt;input id="id_airline_for_17" class="arrival_transfer_toggle_17" type="text" maxlength="30" name="airline_for_17"/&gt;     &lt;label for="id_flight_number_for_17"&gt;Flight Number&lt;/label&gt;:     &lt;input id="id_flight_number_for_17" class="arrival_transfer_toggle_17" type="text" maxlength="30" name="flight_number_for_17"/&gt;      -- snip --  &lt;/form&gt;   EDIT: I should update that i want to be able to perform some action when the input is clicked but only for classes with a matching id at the end.  To make it easy, lets say I want all inputs with a matching id at the end of the #id to disappear when one is clicked (just for arguments sake).
23400
How do I remove items from, or add items to, a select box? I'm running jQuery, should that make the task easier. Below is an example select box.  &lt;select name="selectBox" id="selectBox"&gt;     &lt;option value="option1"&gt;option1&lt;/option&gt;     &lt;option value="option2"&gt;option2&lt;/option&gt;     &lt;option value="option3"&gt;option3&lt;/option&gt;     &lt;option value="option4"&gt;option4&lt;/option&gt;     &lt;/select&gt;