Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

JavaScript Alert In IE - Not Working

Featured Replies

Hi All,

 

I have recently tried to add an age verification script to one of my websites.

 

When the user visits the page its asks for their date of birth. if their over 18 it forwards them to the correct page and if there not then an alert box pops up saying so and does not let them proceed any further.

 

This script works fine in Firefox, but in IE it lets them view the page regardless of if there over 18 or not.

 

 

***Form*** - I have removed the form action for posting purposes

<h1>Age Verification Check</h1>
           <div align="center">
             <p> </p>
             <p><strong>Due to the nature of these photos, please prove that you are 18 or over.</strong></p>
             <p> </p>
             <form action="Removed" method="get" name="age_form">
               Day:
               <select name="day">
                 <option>1</option>
                 <option>2</option>
                 <option>3</option>
                 <option>4</option>
                 <option>5</option>
                 <option>6</option>
                 <option>7</option>
                 <option>8</option>
                 <option>9</option>
                 <option>10</option>
                 <option>11</option>
                 <option>12</option>
                 <option>13</option>
                 <option>14</option>
                 <option>15</option>
                 <option>16</option>
                 <option>17</option>
                 <option>18</option>
                 <option>19</option>
                 <option>20</option>
                 <option>21</option>
                 <option>22</option>
                 <option>23</option>
                 <option>24</option>
                 <option>25</option>
                 <option>26</option>
                 <option>27</option>
                 <option>28</option>
                 <option>29</option>
                 <option>30</option>
                 <option>31</option>
               </select>
               Month:
               <select name="month">
                 <option>1</option>
                 <option>2</option>
                 <option>3</option>
                 <option>4</option>
                 <option>5</option>
                 <option>6</option>
                 <option>7</option>
                 <option>8</option>
                 <option>9</option>
                 <option>10</option>
                 <option>11</option>
                 <option>12</option>
               </select>
               Year:
               <select name="year">
                 <option>2003</option>
                 <option>2002</option>
                 <option>2001</option>
                 <option>2000</option>
                 <option>1999</option>
                 <option>1998</option>
                 <option>1997</option>
                 <option>1996</option>
                 <option>1995</option>
                 <option>1994</option>
                 <option>1993</option>
                 <option>1992</option>
                 <option>1991</option>
                 <option>1990</option>
                 <option>1989</option>
                 <option>1988</option>
                 <option>1987</option>
                 <option>1986</option>
                 <option>1985</option>
                 <option>1984</option>
                 <option>1983</option>
                 <option>1982</option>
                 <option>1981</option>
                 <option>1980</option>
                 <option>1979</option>
                 <option>1978</option>
                 <option>1977</option>
                 <option>1976</option>
                 <option>1975</option>
                 <option>1974</option>
                 <option>1973</option>
                 <option>1972</option>
                 <option>1971</option>
                 <option>1970</option>
                 <option>1969</option>
                 <option>1968</option>
                 <option>1967</option>
                 <option>1966</option>
                 <option>1965</option>
                 <option>1964</option>
                 <option>1963</option>
                 <option>1962</option>
                 <option>1961</option>
                 <option>1960</option>
                 <option>1959</option>
                 <option>1958</option>
                 <option>1957</option>
                 <option>1956</option>
                 <option>1955</option>
                 <option>1954</option>
                 <option>1953</option>
                 <option>1952</option>
                 <option>1951</option>
                 <option>1950</option>
                 <option>1949</option>
                 <option>1948</option>
                 <option>1947</option>
                 <option>1946</option>
                 <option>1945</option>
                 <option>1944</option>
                 <option>1943</option>
                 <option>1942</option>
                 <option>1941</option>
                 <option>1940</option>
                 <option>1939</option>
                 <option>1938</option>
                 <option>1937</option>
                 <option>1936</option>
                 <option>1935</option>
                 <option>1934</option>
                 <option>1933</option>
                 <option>1932</option>
                 <option>1931</option>
                 <option>1930</option>
                 <option>1929</option>
                 <option>1928</option>
                 <option>1927</option>
                 <option>1926</option>
                 <option>1925</option>
                 <option>1924</option>
                 <option>1923</option>
                 <option>1922</option>
                 <option>1921</option>
                 <option>1920</option>
                 <option>1919</option>
                 <option>1918</option>
                 <option>1917</option>
                 <option>1916</option>
                 <option>1915</option>
                 <option>1914</option>
                 <option>1913</option>
                 <option>1912</option>
                 <option>1911</option>
                 <option>1910</option>
                 <option>1909</option>
                 <option>1908</option>
                 <option>1907</option>
                 <option>1906</option>
                 <option>1905</option>
                 <option>1904</option>
                 <option>1903</option>
               </select>
               <input type="submit" name="date" value="Go" onClick="return checkAge()">
             </form>
           </div>

 

***Javascript Age Check***

	function checkAge()
	{
		var min_age = 18;

		var year = parseInt(document.forms["age_form"]["year"].value);
		var month = parseInt(document.forms["age_form"]["month"].value) - 1;
		var day = parseInt(document.forms["age_form"]["day"].value);

		var theirDate = new Date((year + min_age), month, day);
		var today = new Date;

		if ( (today.getTime() - theirDate.getTime()) < 0) {
			alert("Sorry, You Are Too Young To Enter This Page!");
			return false;
		}
		else {
			return true;
		}
	}

Looks like good old IE is being too strict again!

 

Your JS is telling the browser to look for the looking for value of the inputs but you haven't set any in your options lists. All the other browsers are smart enough to realise that and pick up the text instead but IE won't.

 

You'll either need to change all your options to this format:

<option value="1903">1903</option>

 

Or change the JS to pick up the text instead of the value.

  • Author

Looks like good old IE is being too strict again!

 

Your JS is telling the browser to look for the looking for value of the inputs but you haven't set any in your options lists. All the other browsers are smart enough to realise that and pick up the text instead but IE won't.

 

You'll either need to change all your options to this format:

<option value="1903">1903</option>

 

Or change the JS to pick up the text instead of the value.

 

Many thanks for your help!, i just changed the formatting and it all works fine :)

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.