Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery .prop("disabled", false) is not enabling an input

Tags:

I'm having a problem re-enabling an input after it has been disabled on the page load.

I'm using two inputs to accept two dates, but I want it that the second input is not enabled until the first one has a value.

<div id="date1" data-role="fieldcontain">     <label for="date1-start" id="date1-startlbl">Start Date</label>     <input name="date1-start" id="date1-start" type="date" data-role="datebox"data-options='{"mode": "calbox", "overrideDateFormat": "%Y-%m-%d", "beforeToday": true}' data-theme="a" onchange="showdate()"/>     <label for="date1-end" id="date1-endlbl">End Date</label>        <input name="date1-end" id="date1-end" type="date" data-role="datebox" data-options='{"mode": "calbox", "overrideDateFormat": "%Y-%m-%d", "beforeToday": true}' data-theme="a" onchange="datechart()"/> </div> 

The second input is disabled successfully on the page load with.

$("#date1-end").prop("disabled", true); 

The first date has an onchange event that calls the following function

function showdate(){     if ($("#date1-start").val() != null){         if ($("#date1-end").val() != ""){             datechart();         }         else{             $("#date1-end").prop("disabled", false);             $("#date1-end").trigger('change');         }     } } 

The function is called and prop("disabled", false) when reached fires without any errors, but the input remains disabled. The trigger('change') I am using is an attempt at refreshing the element but the same problem exists without it.

I have tried different variations of .attr from an older version of Jquery but I also get the same problem.

I am using Jquery 1.9.1, Jquery-mobile 1.3.1 and PhoneGap 2.7.0

like image 737
RichardMc Avatar asked Jul 04 '13 11:07

RichardMc


People also ask

How check textbox is enabled or disabled in jQuery?

You can use $(":disabled") to select all disabled items in the current context. To determine whether a single item is disabled you can use $("#textbox1").is(":disabled") .

How do I enable and disable a div in HTML?

css("display", "none"); $('#AcquiringBankListdiv'). css("display", "block"); /* Enable the Validator. */ ValidatorEnable(document. getElementById('AcqBankListReqFielValid'), true); /* Disable the Validator.

How do I set the value of a element in jQuery?

jQuery val() Method The val() method returns or sets the value attribute of the selected elements. When used to return value: This method returns the value of the value attribute of the FIRST matched element.


2 Answers

Had the same problem some time ago:

$("#date1-end").prop("disabled", null); 

@Gautam3164's answer is also good.

like image 157
ElmoVanKielmo Avatar answered Sep 20 '22 16:09

ElmoVanKielmo


Try with removeAttr like

$("#date1-end").removeAttr("disabled"); 

You can also try with prop like

$("#date1-end").prop("disabled",false); 
like image 42
Gautam3164 Avatar answered Sep 19 '22 16:09

Gautam3164