Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Mar 2010
    Posts
    235
    Thanks
    39
    Thanked 6 Times in 6 Posts

    jQuery click event not firing

    When hitting the return key on the password field name="pass", the click event is not firing. form.submit is not an option since we need the click event to fire first.

    We are using Drupal 7. Any thoughts?

    PHP Code:
    <div id="login-form-f" style="display:none;">
    <
    form action="/news" method="post" id="user-login" accept-charset="UTF-8"><div><div class="form-item form-type-textfield form-item-name">
      <
    label for="edit-name--2">E-mail <span class="form-required" title="This field is required.">*</span></label>
     <
    input type="text" id="edit-name--2" name="name" value="" size="60" maxlength="60" class="form-text required" />
    <
    div class="description">Enter your e-mail address.</div>
    </
    div>
    <
    div class="form-item form-type-password form-item-pass">
      <
    label for="edit-pass--3">Password <span class="form-required" title="This field is required.">*</span></label>
     <
    input onkeypress="jQuery(&quot;input&quot;).keydown(function(e) {if (e.keyCode == 13) {jQuery(&quot;input[type=submit]&quot;, this).click();}});" type="password" id="edit-pass--3" name="pass" size="60" maxlength="128" class="form-text required" />
    <
    div class="description">Enter the password that accompanies your e-mail.</div>
    </
    div>
    <
    input type="hidden" name="form_build_id" value="form-5GMspHjNPDFEVLo2M58m-SWaDWtHKtFrmWlNUTJuNYo" />
    <
    input type="hidden" name="form_id" value="user_login" />
    <
    div class="form-actions form-wrapper" id="edit-actions--2"><input type="submit" id="edit-submit--2" name="op" value="Log in" class="form-submit" /></div></div></form
    Last edited by mathceleb; 09-19-2012 at 07:55 PM.

  • #2
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,607
    Thanks
    6
    Thanked 997 Times in 970 Posts
    You need to trigger() the click event.

  • #3
    Regular Coder
    Join Date
    Mar 2010
    Posts
    235
    Thanks
    39
    Thanked 6 Times in 6 Posts
    Tried this with no success. Nothing happens: Also, I confirmed that the section of code withi keycode==13 is being called by setting an alert. It is just the button press portion that is not happening.

    PHP Code:
    <input id="edit-pass--3" class="form-text required" type="password" maxlength="128" size="60" name="pass" onkeypress="jQuery("input").keydown(function(e) {if (e.keyCode == 13) {jQuery("#edit-submit--2").trigger("click");}});"> 
    Last edited by mathceleb; 09-19-2012 at 09:20 PM.

  • #4
    Regular Coder
    Join Date
    Mar 2010
    Posts
    235
    Thanks
    39
    Thanked 6 Times in 6 Posts
    Update, we traced this on a debugger and the button is getting clicked, but the form is not being submitted.

  • #5
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,607
    Thanks
    6
    Thanked 997 Times in 970 Posts
    For what do you need the click event anyway?

  • #6
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    You cannot embed double-quotes " within double-quotes without escaping them. Alternatively, replace the (inner) quotes with apostrophes ' as shown:

    Code:
    <input id="edit-pass--3" class="form-text required" type="password" maxlength="128" size="60" name="pass" onkeypress="jQuery('input').keydown(function(e) {if (e.keyCode == 13) {jQuery('#edit-submit--2').trigger('click');}});">
    Your original code seems to indicate that you need to use & quot; - perhaps a restriction of Drupal? Then try & apos; instead (without the space).

    BTW click() is a shortcut for trigger('click').
    Last edited by AndrewGSW; 09-20-2012 at 11:16 PM.
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •