using placeholders where value is empty

I am using the form where in a situation i have to use place holder or title to insert the value in the database, i know we can use

$form.serialize which picks all the values of the form, but in my case value field is always going to be empty and i want to pick placeholders value and title value if placeholder is not defined just like serialization,

is there custom build jquery code or something already build in, how can i can use it just like $(form).serializePlaceholder or $(form).serializetITLE
LVL 16
Gurpreet Singh RandhawaCEOAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
There is not built in function but you could do something like this

Why don't you default the value of the control to the placeholder value if the value is empty when you render the form.

For inputs you could do something like this before you do the serialize
<script>
$(function() {
  $('form').submit(function() {
    // GET AN ARRAY OF ALL INPUTS THAT ARE EMPTY
    var emptyInputs = $('input', $(this)).filter(function() { return this.value ==""; });

    // ITERATE THROUGH THE ARRAY AND SET THE value TO THE 
    // placeholder ATTRIBUTE
    emptyInputs.each(function() {
      this.value = $(this).attr('placeholder');
    });  

    // NOW SERIALIZE
    data = $(this).serialize();
    return false;
  });
});
</script>

Open in new window

Working sample here
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Gurpreet Singh RandhawaCEOAuthor Commented:
i will check it
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.