?
Solved

Javascript Anytime ajax plugin dateplus and dateminus buttons

Posted on 2013-02-06
2
Medium Priority
?
545 Views
Last Modified: 2013-02-07
I'm trying to create an up/down button control which will advance or subtract the from and to date fields by 1 day. This should be simple but my issue lie's somewhere in my referencing #rangeFrom

    dplus.setHours(0,0,0,0);
//    dplus.setDate(dplus.getDate()+1);
//    dplus.rangeConv.parse($("#rangeFrom").val()).getTime());
//    dplus.setDate(dplus.getdate()+1);
    $("#dayplus").click(function(e){$("#rangeFrom").val(rangeConv.format(dplus)).change(); } );
    $("#dayminus").click(function(e){$("#rangeFrom").val(rangeConv.format(dminus)).change(); } );

<html>
  <head>
    <title>Reporting</title>
    <link rel="stylesheet" type="text/css" href="anytime.css" />
    <link rel="stylesheet" href="/jqwidgets/styles/jqx.base.css" type="text/css"/>
    <script type="text/javascript" src="jquery.js"></script>
    <script type="text/javascript" src="anytime.js"></script>
    <script type="text/javascript" src="/jqwidgets/jqxcore.js"></script>
    <script type="text/javascript" src="/jqwidgets/jqxbuttons.js"></script>
    <script type="text/javascript" src="/jqwidgets/jqxscrollbar.js"></script>
    <script type="text/javascript" src="/jqwidgets/jqxlistbox.js"></script>
  </head>

   <style type="text/css">
    #rangeFrom, #rangeTo {
    background-image:url("calendar.png");
    background-position:right center;
    background-repeat:no-repeat; }
   </style>

   <style type="text/css">
    #rangeFromTime, #rangeToTime {
    background-image:url("clock.png");
    background-position:right center;
    background-repeat:no-repeat; }
   </style>

   <style type="text/css">
    #main { margin : 0 auto; }
   </style>

   <style type="text/css">
    #dayplus {
    background-image:url("uparrow.png"); }
   </style>

   <style type="text/css">
    #dayminus {
    background-image:url("downarrow.png"); }
   </style>

   <body>
    <div id="main">
    <form action="reporting.php" method="post">
    </br>
    <table border="0">
    <tr width='50%'>
    <td align='center' valign='top'>
      <table border="0">
        <tr>
         <td>FROM:</td>
         <td align='left'><input type="text" id="rangeFrom" name="rangeFrom" value="" size="22" /><input type="button" id="dayplus" style="width:20px" /><input type="button" id="rangeToday" value="today" style="width:70px" /><input type="button" id="rangeYesterday" value="yesterday" style="width:70px" /></td>
        </tr>
        <tr>
         <td>TO:</td>
         <td align='left'><input type="text" id="rangeTo" name="rangeTo" value="" size="22" /><input type="button" id="dayminus" style="width:20px" /><input type="button" id="rangeClear" value="clear" style="width:70px" /></td>
        </tr>
      </table>
      <div id='jqxlistbox'>
      </div>
        <div style="margin-top: 20px;">
         <input id="button" type="submit" value="Run Report" />
         </br>
         </br>
         </br>
         <div id="eventlog"></div>
        </div>
      </form>
      </div>
    </body>

    <script>
    $(window).load(function(){$('#rangeTo').val('').attr('disabled','disabled');})
    var oneDay = 24*60*60*1000;
    var rangeFormat = "%m/%d/%Z %r";
//"%d-%b-%Y";
    var rangeConv = new AnyTime.Converter({format:rangeFormat});
    var d = new Date();
    d.setHours(0,0,0,0);
    d.setDate(d.getDate()-1);
    var d2 = new Date();
    d2.setHours(0,0,0,0);
    var dplus = new Date($("#rangeFrom"));
    dplus.setHours(0,0,0,0);
//    dplus.setDate(dplus.getDate()+1);
//    dplus.rangeConv.parse($("#rangeFrom").val()).getTime());
//    dplus.setDate(dplus.getdate()+1);
    $("#dayplus").click(function(e){$("#rangeFrom").val(rangeConv.format(dplus)).change(); } );
    $("#dayminus").click(function(e){$("#rangeFrom").val(rangeConv.format(dminus)).change(); } );
    $("#rangeToday").click( function(e){$("#rangeFrom").val(rangeConv.format(d2)).change(); } );
    $("#rangeClear").click( function(e){$("#rangeFrom").val("").change(); } );
    $("#rangeYesterday").click( function(e){$("#rangeFrom").val(rangeConv.format(d)).change(); } );
    $("#rangeFrom").AnyTime_picker({format:rangeFormat});
    $("#rangeFrom").change( function(e) { try {
      var fromDay = rangeConv.parse($("#rangeFrom").val()).getTime();
      var dayLater = new Date(fromDay);
      dayLater.setHours(23,59,59,999);
      var ninetyDaysLater = new Date(fromDay+(90*oneDay));
      ninetyDaysLater.setHours(23,59,59,999);
    $("#rangeTo").AnyTime_noPicker().removeAttr("disabled").val(rangeConv.format(dayLater)).AnyTime_picker({ earliest: dayLater,format: rangeFormat,latest: ninetyDaysLater });
      } catch(e){ $("#rangeTo").val("").attr("disabled","disabled"); } } );
            // below code is for listbox
            $(document).ready(function () {
                var source = [
                    "REPORT: TESTREPORT",
                        ];
                // Create a jqxListBox
                $("#jqxlistbox").jqxListBox({ source: source, width: '400px', height: '200px' });
                // disable the sixth item.
                //$("#jqxlistbox").jqxListBox('disableAt', 6);
                // bind to 'select' event.
                $('#jqxlistbox').bind('select', function (event) {var args = event.args;
                    var item = $('#jqxlistbox').jqxListBox('getItem', args.index);
                    $("#eventlog").html('Report Selected:  ' + item.label);
                });
                $("#button").jqxButton();
                $("#button").click(function () {var item = $('#jqxlistbox').jqxListBox('getSelectedItem');
                });
            });
    </script>
</html>

Open in new window

0
Comment
Question by:Dalexan
2 Comments
 
LVL 83

Accepted Solution

by:
leakim971 earned 2000 total points
ID: 38863674
Your first error is line 73, you close the window.onload event

Test page : http://jsfiddle.net/jPwDa/
$(document).ready(function(e) {
	$('#rangeTo').val('').attr('disabled','disabled');
	var oneDay = 24*60*60*1000;
	var rangeFormat = "%m/%d/%Z %r";
	var rangeConv = new AnyTime.Converter({format:rangeFormat});
	$("#dayplus").click(function(e){
        var d = $("#rangeFrom").val();
        try { d = rangeConv.parse(d) } catch(e) { d = new Date() };
        d.setHours(0);
        d.setMinutes(0);
        d.setSeconds(0);
        var dplus = d.setDate(d.getDate()+1);
		$("#rangeFrom").val(rangeConv.format(new Date(dplus))).change();
	});
	$("#dayminus").click(function(e){
        var d = $("#rangeTo").val();
        try { d = rangeConv.parse(d) } catch(e) { d = new Date() };
        d.setHours(0);
        d.setMinutes(0);
        d.setSeconds(0);
        var dminus = d.setDate(d.getDate()-1);
		$("#rangeTo").val(rangeConv.format(new Date(dminus))).change();
	});
	$("#rangeToday").click(function(e){
        var d = new Date();
        d.setHours(0);
        d.setMinutes(0);
        d.setSeconds(0);
		$("#rangeFrom").val(rangeConv.format(d2)).change();
	});
	$("#rangeClear").click(function(e){
		$("#rangeFrom").val("").change();
	});
	$("#rangeYesterday").click( function(e){
        var d = new Date();
        d.setHours(0);
        d.setMinutes(0);
        d.setSeconds(0);
        d.setDate(d.getDate()-1);
		$("#rangeFrom").val(rangeConv.format(d)).change();
	});
	$("#rangeFrom").AnyTime_picker({format:rangeFormat});
	$("#rangeFrom").change( function(e) {
		try {
			var fromDay = rangeConv.parse($("#rangeFrom").val()).getTime();
			var dayLater = new Date(fromDay);
			dayLater.setHours(23,59,59,999);
			var ninetyDaysLater = new Date(fromDay+(90*oneDay));
			ninetyDaysLater.setHours(23,59,59,999);
			$("#rangeTo").AnyTime_noPicker().removeAttr("disabled").val(rangeConv.format(dayLater)).AnyTime_picker({ earliest: dayLater,format: rangeFormat,latest: ninetyDaysLater });
		} catch(e){ 
			$("#rangeTo").val("").attr("disabled","disabled");
		}
	});

	// below code is for listbox
	var source = [ "REPORT: TESTREPORT"];
	// Create a jqxListBox
	$("#jqxlistbox").jqxListBox({ source: source, width: '400px', height: '200px' });
	// disable the sixth item.
	//$("#jqxlistbox").jqxListBox('disableAt', 6);
	// bind to 'select' event.
	$('#jqxlistbox').bind('select', function (event) {var args = event.args;
		var item = $('#jqxlistbox').jqxListBox('getItem', args.index);
		$("#eventlog").html('Report Selected:  ' + item.label);
	});
	$("#button").jqxButton();
	$("#button").click(function () {
		var item = $('#jqxlistbox').jqxListBox('getSelectedItem');
	})

});

Open in new window

0
 

Author Closing Comment

by:Dalexan
ID: 38864042
Superior, Thanks much.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses
Course of the Month15 days, 6 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question