Jump to content

Function Doesn't Work In Ie But In Firefox...


Cyber_Star

Recommended Posts

Hi, I'm new to javascript. Here is the simple javascript that written for in the webpage.The process is to let user key in info and prompt them to enter info without leaving blank fields. My problem is, in firefox browser, user is being prompt to key in balnk fields but not in IE. I just dont know why it doesn't work in IE but it does work in firefox. Does anyone know why? Please help.Anyway, should i use another function in order to check the condition? for example: the JS form validation

	function goTest(action) {	if (action=="checkNull"){			    if (document.getElementById('name').value  == null || document.getElementById('name').value  == ""){	        document.getElementById('name').focus();		alert('Name field cannot be blank. Please enter your name!')		return false;		}				    if (document.getElementById('age').value  == null || document.getElementById('age').value  == ""){	       document.getElementById('age').focus();	                alert('Please enter your age!')		return false;		}			 }	 return true;                 }

This is the part for html that will call the function to check for null conditions in my webpage fields.

<form name="edit" method="post" action="update.svdo" onsubmit="return goTest('checkNull')">

......continue...

<div align="center">		<input type="submit" value="Save Record  "  class="MFButton">		<input type='button' value=" Delete Record " onclick='go("Delete")'>		<input type="button" value="  Back  " class="MFButton" onClick="java script:document.location.href='main.tpl'">		<div>

Link to comment
Share on other sites

just tested it with minimum code below andit worked in all browsers.NOTE: remove the space between java script, pasting code here forces a space between java and script in 'javascript'.<!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>Untitled Document</title><script type="text/javascript">/*<![CDATA[*//*---->*/function goTest(action) {if (action=="checkNull"){if (document.getElementById('name').value == null || document.getElementById('name').value == ""){document.getElementById('name').focus();alert('Name field cannot be blank. Please enter your name!')return false;}if (document.getElementById('age').value == null || document.getElementById('age').value == ""){document.getElementById('age').focus();alert('Please enter your age!')return false;}}return true;}/*--*//*]]>*/</script> </head><body><form action="update.svdo" method="post" name="edit" id="edit" onsubmit="return goTest('checkNull')"><div align="center"><input type="text" name="name" id="name" /><input type="text" name="age" id="age" /><input type="submit" value="Save Record " class="MFButton" /><input type='button' value=" Delete Record " onclick='go("Delete")' /><input type="button" value=" Back " class="MFButton" onclick="java script:document.location.href='main.tpl'" /></div></form></body></html>

Link to comment
Share on other sites

Hi thanks for your reply ...But what is the main reason causing this to happen? Anyway in my code, the "java" and "script" are not separated.I found out a solution to solve the problem as shown below.

		function ValidateRequired(field, alerttxt)	{		with(field) {			if (value== null || value==""){			alert(alerttxt)			return false;			}			else{			return true;			}		}	} 	 	function ValidateAge(field, alerttxt) 	{ 	with(field) { 		if(value==0) 		{alert(alerttxt) 		return false;} 		else{return true;} 	} 	} 	 	function validate_form(thisform){ 		with (thisform){ 		if(ValidateRequired(name, "Name field cannot be blank. Please enter your name!")==false) 		{name.focus();return false;} 		else if(ValidateAge(age, "Age cannot be zero! Please verify!")==false) 		{age.focus();return false;} 		} 	}

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...