Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
MODX - Register - DOB done on Frontend
<section>
<label>Birth Date </label>
<select id="birthMonth">
<option value="0">January</option>
<option value="1">February</option>
<option value="2">March</option>
<option value="3">April</option>
<option value="4">May</option>
<option value="5">June</option>
<option value="6">July</option>
<option value="7">August</option>
<option value="8">September</option>
<option value="9">October</option>
<option value="10">November</option>
<option value="11">December</option>
</select>
<select id="birthDay">
<option value="01">01</option>
<option value="02">02</option>
<option value="03">03</option>
<option value="04">04</option>
<option value="05">05</option>
<option value="06">06</option>
<option value="07">07</option>
<option value="08">08</option>
<option value="09">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>
<select id="birthYear">
<option value="">Select</option>
<option value="2014">2014</option>
<option value="2013">2013</option>
<option value="2012">2012</option>
<option value="2011">2011</option>
<option value="2010">2010</option>
<option value="2009">2009</option>
<option value="2008">2008</option>
<option value="2007">2007</option>
<option value="2006">2006</option>
<option value="2005">2005</option>
<option value="2004">2004</option>
<option value="2003">2003</option>
<option value="2002">2002</option>
<option value="2001">2001</option>
</select>
<input type="hidden" name="dob" id="dob" value="">
</section>
<script>
$('#birthYear,#birthDay,#birthMonth').on('change', function(){
//inputs
var birth_month = $('#birthMonth').val();
var birth_day = $('#birthDay').val();
var birth_year = $('#birthYear').val();
//create date
var theBirthDay = new Date();
theBirthDay.setMonth(birth_month,birth_day);
theBirthDay.setFullYear(birth_year);
var formattedDate = (Date.parse(theBirthDay)/1000).toFixed(0);
//formattedDate - 2009-07-27 == 1248716903
//MODX DB - 2009-07-27 == 1248670800
$("#dob").val(formattedDate);
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.