jQuery Events

jQuery Events Events are action points while surfing a web page.
A user may click a button for a form submission. Also, a particular user will click a hyperlink and so on.
JQuery has built-in functions to handle events.
Jquery also has the feature to fire an event from the code.

Some Examples:

Suppose, I have a login form on my home page as follows:

<form action="index.php" method="GET" enctype="application/www-x-urlencoded">
	<input type="text" placeholder="Enter username" name="username" />
	<input type="password" placeholder="Enter password" name="password" />
	<input type="submit" value="Login" />
</form>

Suppose I want to store the username in a cookie whenever the user successfully logged in :- we use


$(document).ready(function(){
	$('form')[0].onSubmit = function() {
		let name = $(this).username;
		let password = $(this).password;
		if(name.length==0) 
			return false;
		if(password.length==0)
			return false;
	document.cookie+=("Username: " + name);
	}
});

The above code will check if the username and password are present and if not the form will not be submitted and if both are present The user name is appended to the cookie anmd sent to the server.

Comments

Popular posts from this blog

Parallel Database design, query processing

Laravel | PHP | Basics | Part 2

Apache Hadoop | Running MapReduce Jobs