Source language: Translate to:

Date between range...

General questions about NeoAppBuilder - our rapid application development tool for building HTML5, web and mobile apps.

Moderator: Neosoft Support

Date between range...

Postby David de Argentina » Fri Oct 02, 2015 4:31 pm

Hi all,

I'm doing a HTML / javascript program that allow user select a date between range.

Min date must be today
Max date must be today + 30 days.

I'm working with this html:

Code: Select all
<!DOCTYPE html>
<html>
<head>

<script>
function init() {
  var today = new Date();
  var dd = today.getDate();
  var mm = today.getMonth()+1; //January is 0!
  var yyyy = today.getFullYear();
  if(dd<10){
    dd='0'+dd
  }
  if(mm<10){
    mm='0'+mm
  }
  var today = yyyy+'/'+mm+'/'+dd;
  var hoy = today;


  document.getElementById("fecha").min = hoy;

// *******************************************

  var en30 = new Date();
  en30.setDate(en30.getDate() + 30);

  var today = new Date(en30);
  var dd = today.getDate();
  var mm = today.getMonth()+1; //January is 0!
  var yyyy = today.getFullYear();
  if(dd<10){
    dd='0'+dd
  }
  if(mm<10){
    mm='0'+mm
  }
  var today = yyyy+'/'+mm+'/'+dd;
  var en30 = today;

  document.getElementById("fecha").max = en30;
}


function validate() {
  var f = document.getElementById('fecha').value ;
  if (f == "") {
    alert("you must select a date");
  } else {
    alert(f);
  }
}
</script>

</head>

<body onload="init()">
  <input type="date" id="fecha" min="" max="" >
  <input type="button" onclick="validate();" value=" Select ">
</body>

</html>


In fact, program works. but not fine...
When i change the date, Min & Max range does not work... i can put any date...
If i check the debugger (chrome):

alert(document.getElementById('fecha').max)
alert(document.getElementById('fecha').min)

I get the correct values, but they does not do nothing on execution time...

Could any tell me what is wrong ?

Thanks in advance,
David de Argentina
User avatar
David de Argentina
 
Posts: 1560
Joined: Mon Apr 04, 2005 4:13 pm
Location: Buenos Aires, Argentina

Re: Date between range...

Postby Neosoft Support » Fri Oct 02, 2015 5:54 pm

Are you trying to do this with NeoAppBuilder?
NeoSoft Support
Neosoft Support
NeoSoft Team
 
Posts: 5603
Joined: Thu Mar 31, 2005 10:48 pm
Location: Oregon, USA

Re: Date between range...

Postby David de Argentina » Fri Oct 02, 2015 6:20 pm

Indirectly... using an iframe within a NeoApp program...
User avatar
David de Argentina
 
Posts: 1560
Joined: Mon Apr 04, 2005 4:13 pm
Location: Buenos Aires, Argentina

Re: Date between range...

Postby Gaev » Fri Oct 02, 2015 6:28 pm

David de Argentina:

1) According to this page ... http://caniuse.com/#search=input%20type%3D%22date%22 ... <input type="date"> is only supported in ...

- Chrome 45
- Opera 32
- Android 44
- Chrome for Android 45

... so, not IE or FF

2) Try this example ... http://www.w3schools.com/html/tryit.asp ... te_max_min ... first in Chrome 45 or later ... then in FF or IE

a) in my Chrome Version 45.0.2454.101 m ... a Date Picker is presented ... and the input box contains dd/mm/yyyy (which is the date format for my Canadian English Regional Setting in Windows).

b) In my Firefox 41.0.1 ... there is no Date Picker ... I believe it treats it like <input type="text"> ... so min and max values are ignored.

Also, note that in the w3schools example, they code ...
Code: Select all
<input type="date" name="bday" max="1979-12-31">

... i.e. yyyy-mm-dd format ... when I use your format of "1979/12/31", Chrome does NOT catch invalid dates.
User avatar
Gaev
 
Posts: 3736
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: Date between range...

Postby David de Argentina » Sat Oct 03, 2015 12:20 pm

Thanks Gaev,

I changed the slash "/" as separator by "-" and works fine.

Thanks a bunch !

David de Argentina
User avatar
David de Argentina
 
Posts: 1560
Joined: Mon Apr 04, 2005 4:13 pm
Location: Buenos Aires, Argentina


Return to General NeoAppBuilder Discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron