views:

72

answers:

1

I have a form with 2 input type="text" , 1 combo box and other contains ( combo box contains equal , after,before & between operators + start date(jquery datepicker)+end date(jquery date picker ) but when i am sending the data to server its not appending date parameters with the url using .serialize().

My approach:

$("form#transactionForm").submit(function() {
    var newUrl = "/cpsb/transactionHistory.do?method=getTransactionHistoryDetails&" +
                 $(this).serialize();

    $("#transactionHistory").jqGrid(
        "setGridParam",
        {"url": newUrl, datatype:"json"}).trigger("reloadGrid");
    return false;
});

mark up:

<form class="transform" id="transactionForm" method="post" action="">
    <fieldset class="ui-widget ui-widget-content ui-corner-all">
        <legend class="ui-widget ui-widget-header ui-corner-all">Transaction History</legend>
        <p>
            <label for="lpn">LPN</label>
            <input id="lpn" name="lpn"/>
        </p>
        <p>
            <label for="sku">SKU</label>
            <input id="sku" name="sku" class="skui ui-widget-content" />
        </p>
        <p>
            <label for="ttype">Transaction Type:</label>
            <select id="ttype" name="tranType" >
            <option value="">Select transaction type</option>
            <option value="100">100-Receipt</option>
            <option value="110">110-Shipment</option>
            <option value="120">120-Pallet Update</option>
            </select>
        </p>
        <p>
            <label for="tdate">Transaction date:</label>
            <select id="tdate" name="date">
                <option value="equalsDate">Equal</option>
                <option>Between</option>
                <option value="beforeDate">Before</option>
                <option value="afterDate">After</option>
            </select>
            <input id="sdate" type="text"  style="width:70px"/>
            <input id="edate" type="text"  style="width:70px"/>
        </p>
        <p>
            <button class="submit" type="submit">Search</button>
        </p>
    </fieldset>
</form>
+1  A: 

The problem is very easy. If you want that the input fields with ids "sdate" and "edate" having datepicker will be serialized under the names startDate and endDate you have to modify your HTML code from

<input id="sdate" type="text"  style="width:70px"/>
<input id="edate" type="text"  style="width:70px"/>

to

<input id="sdate" name="startDate" type="text" style="width:70px"/>
<input id="edate" name="endDate"   type="text" style="width:70px"/>

The function jQuery.serialize() serialize only elements which has name attribute. All your <select> have name attribute so they are serialized.

Oleg
thanks! my bad....can I disable the end date when user select other combo box options instead of between....only on selecting between operator I want to use end date ...
paul
I don't understand exactly what you want, but it seems to me that you find the answer in your question. You can use `$("#edate").removeAttr('name');` to remove `name` attribute or `$("#edate").attr('name', 'startDate');` to restore it
Oleg
i want to disable my second datepicker...only when user select the option "between" from drop down combo box it wil be enable to use the datepicker...
paul
@paul: then you can bind "change" event handler to the drop-down "#tdate" (`$("#tdate").change(function() { ... }`) and if the selected item (`$("#tdate option:selected").text()`) is "Between" then show the second datepicker with `$("#edate").show()` or hide it with `$("#edate").hide()`. If you will see that `$.serialize()` will serialize hidden datepicker, then use the trick with `$("#edate").removeAttr('name')` and `$("#edate").attr('name', 'startDate')`.
Oleg
@Oleg ..can I do like this $("#tdate").change(function(){ if(($("#tdate option:selected").text()) == Between) { $("#edate").show(); } else { $("#edate").hide(); } }); and <input id="edate" name="endDate" type="hidden" style="width:70px;" readonly/>
paul
@paul: It seems be OK! Only instead of `"== Between"` you should use `"=== 'Between'"` and use `readonly="readonly"` instead of only `readonly`.
Oleg
but I .show() is not working ...I am not sure about it moreover I have a datepicker image icon which is also showing ...its a buttonImage..I tried to debuf it in firebug but did n't provide me with information..
paul
@Oleg i have remove text type= "hidden" and dynamically hide using .hide() for all cases except between...so now its working ...still did n't fig out the input type hidden why not showed up using .show()..thanks!
paul