views:

277

answers:

3

With jquery autocomplete I have a hidden input field to store ID because the name gets inputted into the autocomplete field on select.

Like this:

        $("#Clients").result(function (event, data, formatted) {
            if (data) {
                $("#ClientID").val(data["client_ClientNumber"]);
                if (data["ClientName"] && data["client_address1"] && data["client_postcode"] && data["client_postname"]) {
                    $("#ClientDetails").html(
                    "<li class=\"clientNumber\">Client ID: " + data["client_ClientNumber"] + "</li>" +
                    "<li>" + data["ClientName"] + "</li>" +
                    "<li>" + data["client_address1"] + "</li>" +
                    "<li>" + data["client_postcode"] + data["client_postname"] + "</li>"
                    );
                }
}

This is my HTML:

    <div id="ClientSelectionPlaceholder">
        <h3>Client</h3>
        <%=Html.TextBox("Clients", null, new { @class = "clientsDropDown" })%>
        <%=Html.Hidden("ClientID", null, new { disabled = true}) %>
    </div>

The problem is that this hidden ClientID field is not posting back nor it does serialize with jquery.serialize(). It is always missing. But as far as I can tell my code looks fine.

+2  A: 

Why have you disabled the hidden field? Don't.

David Morton
+3  A: 

It is because the field is disabled.

...new { disabled = true}...
Sohnee
+2  A: 

When you set the disabled attribute to an input element it's value is NOT posted:

<%=Html.Hidden("ClientID", null, new { disabled = true}) %>
Darin Dimitrov
Actually I've set this to disabled because I also have some input text fields that are disabled and their values do get posted. So I followed the same principle.
mare