How to get multiple text values in alert using jquery

Manideepgoud
Posted by Manideepgoud under jQuery category on | Points: 40 | Views : 2682
Hi every one,

In this code am gonna explain how to get the multiple text values in alert using html and jquery.

Lets get in to html part
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<p>Login and Register form</p>
<form id="getingValues">
<fieldset>
Name:</br>
<input type="text" name="Name"></br>
Age:</br>
<input type="text" name="Age"></br>
Gender:</br>
<input type="text" name="Gender"></br>
Password:</br>
<input type="password" name="password"></br></br>
<input type="button" value="Login" id="loginbtn">
<input type="button" value="Register" id="Registerbtn">
</fieldset>
</form>
</body>
</html>

In the above code, i have defined the text with Name, Age, Gender and Login and Register buttons.
My aim is to get the text values in the alert by clicking Login and Register Button .
In order to get the alert, we need to add small jquery function.
<script>
$(document).ready(function(){
$("#loginbtn,#Registerbtn").click(function(){
alert($("#getingValues").serialize());
});
});
</script>

In the above function we have defined the
 id="gettingValues"
to the html and we have given the id for login and register.
When the Login button is clicked the id triggers and gives the alert values of the form i.e which we are calling with
  alert($("#getingValues").serialize());

Comments or Responses

Posted by: Baba12 on: 8/23/2018 Level:Starter | Status: [Member] | Points: 10
baba12,

Login to post response