Serializing specific inputs


#1

I know what serialize does...the problem that I am facing is that I want to target/serialize only specific inputs of a form.Let me explain:

Take a look at this fiddle.
Click edit and then the plus sign to add an input box.If you see the HTML the name attribute value of this newly created input is different from the filled ones(form[4][service]).

I want to serialize only these.


#2

Then you'll need to remove all of the other fields from the form before the form gets serialized.


#3

O do not think that this can be done...the other inputs are services that the user has already filled.Removing them is like saying to the user that "they do not exist".


#4

Serialize is an all or nothing thing. It might for example be possible to copy the form fields over to a different unseen form, and serialize that form instead.


#5

I see...I will try to find any workaround.


#6

You can serialize specific input elements as well, it doesn't have to be the whole form. For example like

$('[name$="[service]"]').serialize()

to serialize all input elements where the name ends with [service].


#7

Your code is correct if it was only for one input.
Take a look at the HTML below.

<div class="serv_contain">
      <input placeholder="service" class="services text" name="form[3][service]" type="text" size="40"> 
      <input placeholder="price" class="price text" name="form[3][price]" type="text" size="3"></div>
<div class="show_p_inpts"><input class="price_show" type="radio" name="form[3][price_show]" value="1">yes<input class="price_show" type="radio" name="form[3][price_show]" value="0">no</div>

I want to take the data from 2(service and price) inputs and a radio button(price_show).

The code you gave me is grabbing the value only from service...see the fiddle.


#8

Well yes this was just an example... but you can combine multiple selectors by separating them with commas like so:

$('.service, .price, .price_show')

If you're not sure how to target specific elements in general, you can read a thorough introduction to CSS selectors here.


#9

I do know how to combine multiple selectors in general...
But I do not know how to do it in this specific context.

I have tried various combinations to no avail.


closed #10

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.