How to pass the id name to the jQuery validation and send to the controller?

I have two anchor tag and on click, I have to get the id value.

so I tried below code and I am getting the id. Now after getting the id, I have to display the popup. so popup is also displaying.

<div class="buttonSet">
  <a href="javascript:void(0);" id="sample1">Sample one</a>
  <a href="javascript:void(0);" id="sample2">Sample two</a>
  </div>
$(".buttonSet a").click(function() {
    alert(this.id);//getting the id name, just for an example
    $('#Popup').show();
});

Popup code is

<div class=“” id=“Popup” style=“display:none”>
<form action=“” method=“post” name=“form1” id=“form1” autocomplete=“off”>
<div class=“form-group ffl-wrapper”>
<label for=“name” class=“ffl-label”>Name</label>
<input type=“text” name=“name” class=“form-control” id=“name”>
</div>

  &lt;div class="form-group ffl-wrapper"&gt;
    &lt;label for="email" class="ffl-label"&gt;Email&lt;/label&gt;
    &lt;input type="email" name="email" class="form-control" id="email"&gt;
  &lt;/div&gt;

  &lt;div class="form-group ffl-wrapper"&gt;
    &lt;label for="mobileno" class="ffl-label"&gt;Mobile Number&lt;/label&gt;
    &lt;input type="text" name="mobileno" class="form-control" id="mobileno"&gt;
  &lt;/div&gt;


  &lt;div class="form-group text-center btn_submit_action"&gt;
    &lt;input type="submit" name="send" class="" value="Submit"&gt;
  &lt;/div&gt;
&lt;/form&gt;

</div>

Now I am confused how do I pass the id value to the jQuery validation and how to submit button will work. I mean I have one form and two buttons. The Same form will open on button click. I have to get the information that which button is clicked and pass that button id to the jQuery validation and send to the form. Because I have to store the name of the button which is clicked.

jQuery validation

$(“#form1”).validate({
rules: {
name: {
required: true,
minlength: 3,
lettersonly: true
},
email: {
required: true,
email: true
},
mobileno: {
required: true,
minlength: 10,
maxlength: 10,
number: true
}
},
submitHandler: function(form) {
$.ajax({
url: “//my url”,
type: “POST”,
data: $(‘#form1’).serialize(),
success: function(data) {
$(“#Popup”).hide();
$(“#popup_success”).show();
},
}); // AJAX Get Jquery statment
}
});

#javascript #html #jquery

6 Likes2.50 GEEK