Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Jun 2014
    Posts
    10
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Date problem (add 1 day)

    I have this code that adds one day to a particular date, entered with a JQuery Date picker:
    Code:
    var question1=addDays(document.getElementsByName("RequestDate")[0].value);
    the actual 'addDays' function is:
    Code:
    	function addDays(dt)
    	{
    		var ds = dt.split("/");
    		var startDate = new Date(ds[2], ds[0]-1, ds[1]); 
    		var daysAhead = 1;  // change to 6 for days inclusive of start date - originally 7
    		startDate.setTime(startDate.getTime()+(daysAhead*24*60*60*1000));
    		var futureDate = (startDate.getMonth()+1)+"/"+startDate.getDate()+"/"+startDate.getFullYear();
    		futureDate = futureDate.replace(/^(\d{1}\/)/,"0$1").replace(/(\d{2}\/)(\d{1}\/)/,"$10$2");  // add leading zeroes
    		return futureDate;
    	}
    It works fine in Internet Explorer 9, but in Chrome, it causes my entire form post to fail. There's no error message or anything - it's just that nothing happens.

    Anyone know why?

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,992
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    It works fine for me in IE and Chrome. Look elsewhere for your problem. Is the function actually being called?

    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #3
    New Coder
    Join Date
    Jun 2014
    Posts
    10
    Thanks
    3
    Thanked 0 Times in 0 Posts
    All those lines are in a function submitting the form. When I remove that function from each of the lines, the form submits fine.
    Last edited by ElmoWatson; 06-11-2014 at 05:58 PM.

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,992
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    Quote Originally Posted by ElmoWatson View Post
    All those lines are in a function submitting the form. When I remove that function from each of the lines, the form submits fine.
    Sorry, I do not understand you. What function are you talking about?

    These days there are very few cross-broswer incompatiblities. If it works in IE it ought to work in GC and vice-versa.
    Last edited by Philip M; 06-11-2014 at 06:41 PM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #5
    New Coder
    Join Date
    Jun 2014
    Posts
    10
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Philip M View Post
    Sorry, I do not understand you. What function are you talking about?
    What I mean is that I have a function called 'postSurvey'. All the lines gathering the data from the html form (including the line that gets the data using the 'addDays' function) are inside that function.

    Then, the html markup for the button is:
    Code:
    <input type='button' value='Submit' onclick='javascript:postSurvey();' />

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,992
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    Quote Originally Posted by ElmoWatson View Post
    What I mean is that I have a function called 'postSurvey'. All the lines gathering the data from the html form (including the line that gets the data using the 'addDays' function) are inside that function.

    Then, the html markup for the button is:
    Code:
    <input type='button' value='Submit' onclick='javascript:postSurvey();' />
    Place the action in the form tag.

    <form id = xxx action = yyy onsubmit = postSurvey()>
    and make your button a submit button.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • Users who have thanked Philip M for this post:

    ElmoWatson (06-12-2014)

  • #7
    New Coder
    Join Date
    Jun 2014
    Posts
    10
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Philip M View Post
    Place the action in the form tag.

    <form id = xxx action = yyy onsubmit = postSurvey()>
    and make your button a submit button.
    Oh, if I only could. Unfortunately, we are just providing the html within an already defined framework in which the Form tag is autogenerated.

    Thanks for your help, though - -


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •