jquery - Get a selected radio button value after POST to set other fields enabled/disabled -


I have an MVC application with a simple control to select all the dates or date ranges for all dates.

The DT pickers have an onclick handler in the radio button to enable / disable all the work well so far.

When I try to set the correct reference position for datepickers after a POST, I can not find the jQuery selector to return the check box to the radio selector.

The code is as follows:

  & lt;% = Html.RadioButton ("Date selection. AllDates", "AllDates", Model AllDates == "AllDates", New {onclick = "setReadOnly (this);"})%> All dates & amp; Nbsp; & Lt;% = Html.RadioButton ("DateSelection.AllDates", "Selection", Model.AllDates == "Selection", New {onclick = "setReadOnly (this);"}}% & gt; Selection & lt;% = Html Date Picture ("Date Select. Start Date", Model. Start Date, "", "")%> & amp; nbsp; & amp; nbsp; & lt;% = Html.DatePicker ("Date Selection  

The Javascript is as follows:

   & lt; script type = "text / jscript"> Function set readonly (obje) {if (obj.value == "Selection") {$ ('# dateSelection_startdate'). CSS ('Background Cooler' , '#ffffff') .removeAttr ('readonly') .datepicker ('enable'); $ ('# dateSelection_enddate' ). CSS ('background color', '#ffffff') .removeAttr ('readonly') .Det picker ('enabled');} and {$ ('# date select_startout'). CSS ('background color' , '#eeeeee') .attr ('Read Only', 'Readable') .val ('') .Date Picker ('Disabled'); $ ('# DateSelection_enddate'). CSS ('Background Cooler', ' '#eeeeee') .attr ('readonly', 'readonly') .val ('') .datepicker ('disabled'); }}  

  & lt; Script type = "text / jscript" & gt; $ (Document) .ready (function () {$ ('# dateSelect_startdate') Datepicker ('disable'). CSS ('background caller', '#eeeeee') .attr ('readonly', 'readonly') .val ('', ''); $ ('# date select_dated') Date picker ('disabled'). CSS ('background color', '#eeeeee') .attr ('readable', 'readable' ) .val (''); var selected = $ ('# date_sign__date: check'); setReadOnly (selected);});   

P>

will not return the checked radio button

Using

  var selected = $ ('# dateSelection_AllDates');  

The first radio button will return the value as expected, i.e. the use of the 'checked' filter is always mandatory.

Can anyone see anything here wrong?

I think you need something else like this:

  $ ("Input [name = 'dateSelection_AllDates']: checked")  

It is difficult to tell without seeing your generated HTML, since I do not know MVC clearly You have several radio buttons with the same name (hence a group, yes?). This is not the same as an ID, which should be unique by definition.


Comments