newbe123 Posted December 18, 2010 Share Posted December 18, 2010 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; } Link to comment https://forums.phpfreaks.com/topic/222072-javascript-alert-only-working-on-safari-why/ Share on other sites More sharing options...
haku Posted December 20, 2010 Share Posted December 20, 2010 I didn't look too deeply at your code, but it may have something to do with this: <script src="validate.js" type="text/JavaScript"> it should be this: <script src="validate.js" type="text/javascript"> Link to comment https://forums.phpfreaks.com/topic/222072-javascript-alert-only-working-on-safari-why/#findComment-1149415 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.