Tamer Zoubi @ Drupal 8


Drupal expert | Programmer

javascript

Drupal 7 check if user is logged in from javascript

Drupal 7 comes with jquery cookie plugin which can be find under

misc/jquery.cookie.js

This plugin can be used to check if user is logged in or not directly from Jquery. We do that by checking if the cookie DRUPAL_UID exists and its value is not equal to 0.

Tags
anonymous
authenticated
COOKIE
Drupal 7
drupal_uid
javascript
jquery
jQuery.cookie is not a function
user

Submit a form using Javascript

Usually form is submitted when the user press on a submit button. But , sometimes, you may need to submit the form programmatically using JavaScript.

JavaScript provides the form object that contains the submit() method. Use the 'id' of the form to get the form object.

For example, if the name of your form is 'myform', the JavaScript code for the submit call is:

document.forms["myform"].submit();


But, how to identify a form? Give an id attribute in the form tag:

Tags
javascript