Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8826565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:10:07+00:00 2026-06-14T07:10:07+00:00

Ok A while back I found this wonderful little addon style script for jQuery

  • 0

Ok A while back I found this wonderful little addon style script for jQuery that will take all fields in a form and serialize them into a JSON object. Unfortunately however. I am finding that this function will use the placeholder text if none is otherwise provided. Which if its the case the the placeholder text is the text there I would rather it be set to null.

Any ideas how I can add that into this little snip?

(function($) {
$.fn.serializeFormJSON = function() {

   var o = {};
   var a = this.serializeArray();
   $.each(a, function() {
       if (o[this.name]) {
           if (!o[this.name].push) {
               o[this.name] = [o[this.name]];
           }
           o[this.name].push(this.value || '');
       } else {
           o[this.name] = this.value || '';
       }
   });
   return o;
};
})(jQuery);

edit:
In other words the placeholder attribute could be something like placeholder="First name" and it seems javascript is treating that as an actual value when grabbing the inputs. So Im getting entries for a first name field (optional) as “First name”. So what I’d like is to figure out how to compare the current field the above snip is on, and have it see the current placeholder for that field (if any as things like selects dont have that attribute). And if the value being pulled is a match for the placeholder attribute I want to add that field to the object being created but as null instead of the placeholder text

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T07:10:08+00:00Added an answer on June 14, 2026 at 7:10 am

    Why not just clear the placeholders before you serialize?

    function clearPlaceHolders(){
     var form = document.GetElementById("formId");
     $(form).find("input").each(function(index,el){
      el.removeAttribute("placeholder");
     }
    }
    

    See this for an example: http://jsfiddle.net/WjEK9/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I little while back I posted this question . I have updated that question
A while back a found a great-looking framework that allowed .net developers to implement
A while back I created a lightbox plugin using jQuery that would load a
A while back I switched the way I handled c style errors. I found
A while back i found a website that would allow you to select a
A while back I found some code that allows you to filter the contents
Background A while back, I ran into some behaviour that I found very strange
a while back, CNET had these really cool Social Share buttons, that when you
A while back I was playing with methods using variable-length argument lists (java) that
This is an SQL efficiency question. A while back I had to write a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.