How to remove an input type select from serialize

Asked

Viewed 53 times

0

  • Good morning Guys! Great Friday!!

I’m having a doubt here I’m getting all the data from a form

$.post("salvar_1.php", $("#form").serialize())

More need to remove a select with the name date, serialize, and something else at the end I I pass all the data for $_GET with

var str = $('#data').val() + decodeURIComponent($( "form" ).serialize());
    window.location.replace(str);

This part I managed to take out, @’s @40 for emails, but the spaces keep coming as %20... I can get this I need to clear the url at the end! and without the date variable of select!

  • Good day vlwho, cool serious shows how the values are, how the full url is, how the value is in select and how it is going to the server.

1 answer

0


Vinícius, I think you should pass the data by POST, however, to quickly solve your problem, you could use the selector :not(). Would look like this:

$('form :not(select#data)').serialize();

or using the select name instead of id:

$('form :not(select[name="data"])').serialize();

What would be the equivalent of: select any form minus the id (or name="date") specified.

Reference: https://www.w3schools.com/jquery/sel_not.asp

  • Perfect, it worked now as I remove %20 from the spaces I tried so and it didn’t work! var str = $('#data'). val() + decodeURIComponent($('form :not(select[name="data"])'). serialize(); novaString = str.replace(/%20/g, ' '); window.location.replace(novaString);

  • Vinicius, the %20 from space shall not be removed! the URL breaks because you are passing the data via GET, the treatment to reverse these special characters must be done the application that receives the data!

  • Intendi, thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.