how to prevent isNaN before dates are selected in Datepicker
<p>I would like to prevent NaN from showing up in these text boxes:  "total_full", "total_half", "total_single".  I have <strong>tried</strong> setting the initial value of all calculating / number fields to "0", but "total_single" is still NaN until "check_out" date is selected and the total_days_acc is updated?</p>

<p>I am not sure how much of the code I am supposed to put here, and I would hate to leave something important out, so here is a link to a question where i incorrectly posted "all" the coding.  :</p>

<p><a href="http://stackoverflow.com/questions/11006316/hide-show-fields-based-on-input-value">hide / show fields based on input value</a></p>

<p>Thank you</p>

<pre><code>&lt;td&gt;Accommodation:&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;&lt;p&gt;Check in Date&lt;/p&gt;&lt;/td&gt;
    &lt;td&gt;&lt;input type="text" name="check_in_date" id="check_in_date" class="datepicker" /&gt;&lt;/td&gt;
    &lt;td&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;/td&gt;
    &lt;td&gt;&lt;p&gt;Check out Date&lt;/p&gt;&lt;/td&gt;
    &lt;td&gt;&lt;p&gt;
      &lt;input type="text" name="check_out_date" id="check_out_date" class="datepicker" /&gt;
        &lt;/p&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;Total Days Accommodation&lt;/td&gt;
    &lt;td&gt;&lt;input type="text" name="total_days_acc" id="total_days_acc" /&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Number of Rooms:&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Single&lt;/td&gt;
    &lt;td&gt;&lt;input type="text" name="no_of_rooms_single" id="no_of_rooms_single" /&gt;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;Double / Twin&lt;/td&gt;
    &lt;td&gt;&lt;input type="text" name="no_of_rooms_double" id="no_of_rooms_double" /&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Contact Person&lt;/td&gt;
    &lt;td&gt;&lt;input type="text" name="contact_person" id="contact_person" /&gt;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Telephone Number&lt;/td&gt;
    &lt;td&gt;&lt;input type="text" name="tel_no" id="tel_no" /&gt;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;Fax Number&lt;/td&gt;
    &lt;td&gt;&lt;input type="text" name="fax_no" id="fax_no" /&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Cell Number&lt;/td&gt;
    &lt;td&gt;&lt;input type="text" name="cell_no" id="cell_no" /&gt;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;Email&lt;/td&gt;
    &lt;td&gt;&lt;input type="text" name="email" id="email" /&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Full Day Conference @ R260.00 p/p&lt;/td&gt;
    &lt;td&gt;&lt;input type="text" name="full_day" id="full_day" /&gt;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;Total Cost Full Day&lt;/td&gt;
    &lt;td&gt;&lt;input type="text" name="total_full" id="total_full" readonly="readonly" /&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Half Day Conference @ R240.00 p/p&lt;/td&gt;
    &lt;td&gt;&lt;input type="text" name="half_day" id="half_day" /&gt;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;Total Cost Half Day&lt;/td&gt;
    &lt;td&gt;&lt;input type="text" name="total_half" id="total_half" readonly="readonly" /&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Single Rooms @ R480.00 p/p&lt;/td&gt;
    &lt;td&gt;&lt;input type="text" name="single_rooms" id="single_rooms" /&gt;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;Total Cost Single Rooms&lt;/td&gt;
    &lt;td&gt;&lt;input name="total_single" type="text" id="total_single" readonly="readonly" /&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Double / Twin Rooms @ R720.00 p/p&lt;/td&gt;
    &lt;td&gt;&lt;input type="text" name="double_rooms" id="double_rooms" /&gt;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;Total Cost Double / Twin&lt;/td&gt;
    &lt;td&gt;&lt;input name="total_double" type="text" id="total_double" readonly="readonly" /&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Data Projector @ R400.00 rental p/day&lt;/td&gt;
    &lt;td&gt;&lt;input type="text" name="data_proj" id="data_proj" /&gt;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;Total Cost Projector Rental&lt;/td&gt;
    &lt;td&gt;&lt;input name="total_project" type="text" id="total_project" readonly="readonly" /&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Sub Total&lt;/td&gt;
    &lt;td&gt;&lt;input type="text" name="sub_total" id="sub_total" /&gt;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td height="23"&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;
  &lt;/tr&gt;

  &lt;/form&gt;
&lt;/table&gt;

&lt;/div&gt;

&lt;div id="hideme"&gt;
Hello Hideme
&lt;/div&gt;


&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;

&lt;script type="text/javascript"&gt;
//Datepicker
$(function() {
    $(".datepicker").datepicker({ minDate: -0, maxDate: "+100M +10D",dateFormat: 'dd-mm-yy'})
    ({
        changeMonth: true,
        changeYear: true,
    });
        });

//Datepicker Enquiry Date Set to Today
var enquiry_date = $.datepicker.formatDate('dd-mm-yy', new Date());
document.getElementById('enquiry_date').value = enquiry_date;


//Datepicker Conference in / out
var calcDate = function() {
    var start = $('#conference_date_in').datepicker('getDate');
    var end = $('#conference_date_out').datepicker('getDate');
    var days = (end - start) / 1000 / 60 / 60 / 24 + 1;

    if(days==0) {days=1
    }
    if( days &gt;= 0 ) {
    document.getElementById('total_days').value = days;
    } 
        }


$('#conference_date_out').change(calcDate);
$('#conference_date_in').change(calcDate);




//Datepicker Check in  / Out Accommodation
var calcDateAcc = function() {
    var startacc = $('#check_in_date').datepicker('getDate');
    var endacc = $('#check_out_date').datepicker('getDate');
    var daysacc = (endacc - startacc) / 1000 / 60 / 60 / 24;


    if(daysacc==0) daysacc=1
    if( daysacc &gt;= 0 ) {
    document.getElementById('total_days_acc').value = daysacc;
    } 
        }


$('#check_in_date').change(calcDateAcc);
$('#check_out_date').change(calcDateAcc);



//Calculate Total Cost FullDay Conference
function calculateFull()
{
    var fulldays = parseInt(document.getElementById("full_day").value);

    var no_of_delegates = parseInt(document.getElementById("no_of_delegates").value);

    var fullprice = 260;

    var resultfull =  fulldays * no_of_delegates * fullprice;

    document.getElementById("total_full").value = resultfull;
    }

    $('#full_day').change(calculateFull).keyup(calculateFull);



//Calculate Half Day conference total   

    function calculateHalf()
{
    var halfdays = parseInt(document.getElementById("half_day").value);

    var no_of_delegates = parseInt(document.getElementById("no_of_delegates").value);

    var halfprice = 240;

    var resulthalf =  halfdays * no_of_delegates * halfprice;

    document.getElementById("total_half").value = resulthalf;
    }

    $('#half_day').change(calculateHalf).keyup(calculateHalf);



//Calculate Total Cost Single Rooms
    function calculateSingle()
{
    var single_rooms = parseInt(document.getElementById("single_rooms").value);

    var total_days_acc = parseInt(document.getElementById("total_days_acc").value);

    var single_rooms_price = 480;

    var resultsingle =  single_rooms * total_days_acc * single_rooms_price;

    document.getElementById("total_single").value = resultsingle;
    }

    $('#single_rooms').change(calculateSingle).keyup(calculateSingle);
    $('#check_in_date').change(calculateSingle);
    $('#check_out_date').change(calculateSingle);


//Hide me Testing   
$("#full_day").keyup(function(){

        if ($('#full_day').val() == "1") {   
            $("#hideme").show("fast"); //Slide Down Effect
        }
        else {
            $("#hideme").hide("fast");    //Slide Up Effect
        }
    });
&lt;/script&gt;
</code></pre>
