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 6797889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:39:51+00:00 2026-05-26T18:39:51+00:00

I have the following problem: I have a form I need to serialize but

  • 0

I have the following problem:

I have a form I need to serialize but I am using javascript to change the look of the select fields. This means, the real select fields are hidden using display:none.
My Problem is now, that jQuery does recognize the hidden selects, but only serializes the first value and not the selected one.

<select name="publish">
<option value="1">yes</option>
<option value="2" selected="selected">no</option>
</select>

jQuery.serialzie: publish=1

so it gives me the first and not the correct value.

Any ideas for a workaround?

Solutions
Okay, as mentioned by RobW, the best solution is probably to just let the JavaScript select the option you want by setting the selectElement.selectedIndex = 5

My solution however is a little different, because I do not want to change the plugin used to change the appearance of my selects, due to maintenance problems (as in, needing to change the script every time they release a new version).
I did just use a custom function for serialization.

(function($) {
$.fn.serializer = function() {
    var toReturn    = [];
    var elements         = $(this).find(':input').get();
    $.each(elements, function() {
        if (this.name && !this.disabled && (this.checked || /select|textarea/i.test(this.nodeName) || /text|hidden|password/i.test(this.type))) 
        {
            var val = $(this).val();
            // if is select, check selected
            if(this.nodeName == "SELECT")
            {
                val = $(this).find('option:selected').val();    
            }
            toReturn.push( encodeURIComponent(this.name) + "=" + encodeURIComponent( val ) );
        }
    });
    return toReturn.join("&").replace(/%20/g, "+");
}
})(jQuery);
  • 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-05-26T18:39:52+00:00Added an answer on May 26, 2026 at 6:39 pm

    If the issue is caused by hidden elements, temporary show them before serializing:

    var $form = $('#myForm');
    var hidden = $form.find(':hidden'); // Select all hidden elements
    hidden.show();                      // Show them
    var string = $form.serialize();     // Serialize form
    hidden.hide();                      // Hide them again
    

    Edit: It seems that you’re trying to select an option by setting the selected=selected attribute. You should use selectedIndex to change the selected option:

    var select = $("#myselect")[0]; //DOM element
    select.selectedIndex = 5;       //Example, select 6th option
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got the following problem. When a form is submitted using ajax I need
I have the following form and javascript function on my web page. This is
I have the following problem: I have a form in site/banen (currently local running
I have a following problem, I have HTML form that uploads a file with
I have got a the following problem: I have got multi-step form where in
I have the following problem: I got a view with two text fields and
I have the following problem in a Database using Access 2007 as front end
I've faced the following problem. I'm developing a form for the site and this
I have the following problem: I have a Form named MainForm. I have a
I've found myself with the following problem: I have form with a random number

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.