Bhagirath
Bhagirath

Reputation: 161

Jquery .prop() not workin

I have this code...

 function roundtrip() {
   //alert("Round Trip");
   $("#checkoutdate").prop("disabled", false);
   $("#btncheckoutdate").show();
 }
 function onewaytrip() {
   //alert("One Way Trip");
   $("#checkoutdate").prop("disabled", true);
   $("#btncheckoutdate").hide();
 }

n the html code is

<input type="radio" name="trip_type" id="trip_type" onclick = "return onewaytrip()" value="One_way"> One Way Trip
<input type="radio" name="trip_type" id="trip_type" onclick = "return roundtrip()" checked="checked" value="round_trip"> Round Trip

<label name="depaturedate">Departure Date</label> &nbsp; &nbsp; 
<input id="checkindate" class="font11textbox" type="text" readonly="readonly" style="position: relative;" autocomplete="off" maxlength="12" name="checkindate">
<img id="btncheckindate" border="0" name="btncheckindate" alt="select date" src="images/calendar1.gif">
&nbsp; &nbsp; 
<label name="returndate">Return</label>&nbsp; &nbsp; 
<input id="checkoutdate" class="font11textbox" type="text" readonly="readonly" style="position: relative;" autocomplete="off" maxlength="12" name="checkoutdate">
<img id="btncheckoutdate" border="0" name="btncheckoutdate" alt="select date" src="images/calendar1.gif">
</br>

The aim is to hide/display the calender image n to enable/disable the inputbox on click of the respective radio buttons.

but i'm getting the following error

Uncaught TypeError: Cannot call method 'prop' of null.

it's really bothering me. The code is real simple for the error. I need sum help here.

Upvotes: 1

Views: 1864

Answers (1)

adeneo
adeneo

Reputation: 318182

how about using proper event handlers :

<input type="radio" name="trip_type" id="oneway" value="One_way"> One Way Trip
<input type="radio" name="trip_type" id="roundtrip" value="round_trip" checked> Round Trip

js

jQuery(function($) {
    $('[name="trip_type"]').on('change', function() {
        state = this.checked && this.id == 'oneway';

        $("#checkoutdate").prop("disabled", state);
        $("#btncheckoutdate").toggle(state);
    });
});

FIDDLE

Upvotes: 2

Related Questions