How can i use .not jquery with .serialize

naham 3k :

I want to serialize this form without input name lname Code:

var x = `<form action="/action_page.php">
  <label for="fname">First name:</label><br>
  <input type="text" id="fname" name="fname" value="John"><br>
  <label for="lname">Last name:</label><br>
  <input type="text" id="lname" name="lname" value="Doe"><br><br>
  <input type="submit" value="Submit">
</form> `;
var b =$(x).not("[name=lname]").serialize();
console.log(b);
Rory McCrossan :

To do this you need to call :not() on the input elements within the form, not the form itself. The same goes for the serialize() method. Try this:

var x = `<form action="/action_page.php">
  <label for="fname">First name:</label><br>
  <input type="text" id="fname" name="fname" value="John"><br>
  <label for="lname">Last name:</label><br>
  <input type="text" id="lname" name="lname" value="Doe"><br><br>
  <input type="submit" value="Submit">
</form> `;
var b = $(x).find('input:not([name="lname"])').serialize();
console.log(b);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=302441&siteId=1