Jump to content

JavaScript: alert only working on Safari! Why?


newbe123

Recommended Posts

My problem is that this only works on Safari and not IE, FF!?

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"> 

<head>
	<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />

	<title>JavaScript</title>

	<link rel="stylesheet" type="text/css" href="stilmall.css" />

	<script src="validate.js" type="text/JavaScript">						
	</script>

</head>

<body>

	<h1>JavaScript-sida 2 </h1>		

	<form name="frmInput" method="post" action="mailto:[email protected]" enctype="text/plain" onsubmit="return validate()">
		<p>
			Name:<br />
			<input type="text" name="txtName" size="12" /><br />	
			Key: (123)<br />
			<input type="password" name="txtKey" size="12" /><br />	

			gender:<br />											
			<input type="radio" name="radSex" value="Male" />Male<br />
			<input type="radio" name="radSex" value="Female" />Female<br />

			Ålder:<br />
			<select name="selAge">
				<option value="">Choose age range</option>
				<option value="young">0-17</option>
				<option value="medium">18-64</option>
				<option value="old">65-</option>
			</select>

			<input type="submit" value="OK" />

		</p>

	</form>

</body>

</html> 

 

 

 

 

 

 

JavaScript  (alert only works on Safari!)

 

 

function validate()
{	
var returnValue = true;

var name = frmInput.txtName.value;
var key = frmInput.txtKey.value;	
var sex0 = frmInput.radSex[0].checked;
var sex1 = frmInput.radSex[1].checked;
var age = frmInput.selAge.selectedIndex;	


if (name.length == 0)
{
	alert("Enter name"); // not working
	frmInput.txtName.focus();
	return false;
	}


if (key != "123")
{
	alert("Wrong password!");    //not working
	frmInput.txtKey.focus();
	return false;
}	


if (!sex0 && !sex1)
{
	alert("Enter gender!");   //not working
	frmInput.txtKey.focus();
	return false;
}


if (age == 0)
{
	alert("Enter age range");    // not working
	frmInput.txtKey.focus();
	return false;
}

return true;


}



Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.