Javascript code to skip or assign minutes value to 0

As soon as user clicks submit button how to skip the minutes value from the user input or assign the value to zero and pass value ? In my code im trying to assign the value to zero and pass the value.

Below is my HTML CODE

<input id="dateInputone" name="dateipone" type="datetime-local" step="600" style="display:none;">

          <input type="submit"  value="submit" onclick="validate_time(this.value);">

Below is my javascript CODE

     function validate_time(min)
     {
      var allowed_values = new Array("00");
      var minutes = min.split(':').pop();
     for(var i=0; i = allowed_values.length; i++)
     {
	    if(allowed_values[i] == minutes)
            { 
		return true;
	    } 
	  else
	  { 
		return minutes.push("00"); 
	  }
   }	
  }

@TechnoBear…uve replied some thing …But i’m not able to see your post…

Can’t you just split the time string at the colon and append “00” on the end of it, if you always want minutes to be zero? It seems overkill to loop through a single array element to check whether the end matches, and then replace it if it does not - just replace it in the first place.

function truncate_time(min)
  {
  var timestr = min.split(':');
  return timestr[0] + ":00";
  }

Obviously you’d want some validation in there.

@droopsnoot…thanks mate for the answer …If user as entered zero then no need for me to replace…And if not need to replace it and notify him…So …thanks again…:slight_smile:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.