javascript - I need it to return 0 if blank with jQuery datepicker -
i have html form passes date , time javascript have things done it. jquery used pass variable javascript is:
var pieces; $(document).ready(function() { $('#datepicker').datepicker({ onselect: function(datetext, inst) { window.pieces = datetext.split('/'); $('#day').val(pieces[0]); $('#month').val(pieces[1]); $('#year').val(pieces[2]); } }) });
the javascript used analyze uses:
var day1 = parseint(pieces[1],10);
how can parse blank value datepicker returns error telling me doesn't exist?
presumably initial string 15/05/2013.
the js used analyze uses:
var day1 = parseint(pieces[1],10);
how can parse blank value datepicker returns error telling me doesn't exist?
i'm not sure you're asking. if mean "if original string blank, want value day1 of 0
", can check value , either return value number or 0 depending on result of test:
var day1 = typeof pieces[1] == 'undefined' ? +pieces[1] : 0;
incidentally, code, day1 should peices[0].
Comments
Post a Comment