1

For testing purposes on joomla default login file here: (/templates/theme718/html/com_users/login/default_login.php), I run the following successfully to generate the username and change the language

jQuery(document).ready(function(){
    ....
    jQuery('input#username').val('"+username+"');
    jQuery('#lang option[value=zh-TW]').attr('selected','selected');
    jQuery('#lang').change();
    ...
})

The code generate username into input username field, changes the language from select box.

However, one thing I could not perform following the same logic. That is, triggering 'login' button to be programmatically 'clicked'. I tried the following lines:

jQuery('#login').trigger('click');
jQuery('submit#login').click();

Nothing fired. I have this line in the file:

<button type="submit" style="float:right" class="button loginbtn""><?php echo JText::_('JLOGIN'); ?></button>

So my question, how to fire click event on login button.

  • 1
    It looks like you don't have button with ID "login". You could fire an event with following line: jQuery('.loginbtn').click(); – Sahil Purav May 7 '15 at 9:34
  • @SahilPurav Thanks, this jQuery('.loginbtn').click() worked for me. You may consider add it as an answer. – Hawk May 12 '15 at 9:09
  • Glad I helped you. Please accept my answer so that it will be helpful for other googlers. – Sahil Purav May 12 '15 at 9:16
1

Try this:

jQuery('.loginbtn').click()
  • For multiple reasons, it would be better to avoid try this / code-only answers. You see, 1. It is bad role modeling - future volunteers will see that this type of answer can win the green tick 2. Code-only answers do very little to educate/empower the asker 3. Existing pages are used to close new duplicate questions, so your answer is very unlikely to only "speak" to one person with this issue. Please reinforce this answer with some explanation of what it does, how it works, why you chose it, etc. and perhaps a hyperlink to a credible source. – mickmackusa Feb 1 at 12:15
4

You need to trigger submit on form for login user.

edit: did not see You don't have a login id in your div. so try this:

jQuery('.loginbtn').trigger('click');

and if this not work for you try this:

jQuery('.loginbtn').parents('form').submit();
  • Your answer is very short and I'm not sure if I understand it. How can I trigger login form submission? – Hawk May 7 '15 at 9:14
  • He answered correctly. You cannot downvote this answer as you indeed do not have button with "login" as ID. – Sahil Purav May 7 '15 at 9:36
  • +1, I just made a small edit and used jQuery rather than $ as the OP isn't currently using any alias ;) – Lodder May 7 '15 at 11:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.