Why is the alert message not showing up?Anything wrong in the syntax? <script language="JavaScript"> function validateForm() { var emptystr; var msg = " "; var emptyNum=0; if( (fname.value==null)||(fname.value==" ")||isblank(fname.value) ) { emptyNum++; emptyStr += fname; } if( (lname.value==null)||(lname.value==" ")||isblank(lname.value) ) { emptyNum++; emptyStr += lname; }
if(emptyNum = 1) msg += "The following field is empty:" + emptyStr; else if(emptyNum >1) msg += "The following fields are empty: \n"+emptystr +"\n" alert(msg); return false; } </script>
<form name="reg" method="GET" action="Login" onSubmit="return validateForm();"> <input type ="text" name ="fname" size="10" tabindex="1"> ...... lname is for last name.
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15003
posted
0
one problem if(emptyNum == 1) use should be using document.FormName.ElementName.value; so it works on all broswsers where is fname and lname defined? plus your code is going to alert if it is true I have a meeting so I can not help you out anymore right now... Eric
Lucky Singh
Ranch Hand
Joined: Jan 19, 2004
Posts: 125
posted
0
fname and lname are defined in the form. Didn't understand where I should use document.formname..... Basically I am setting the string msg to some value and displaying it in the end.
Winston Smith
Ranch Hand
Joined: Jun 06, 2003
Posts: 136
posted
0
Everywhere you reference the form field, you should use the syntax: document.FormName.FormField. So, for instance, when you want to reference the lname field, your code should read: document.reg.lname To set the value: document.reg.lname.value="Smith" I think IE will spoil you, and let you reference fields by fieldname only, but don't get spoiled because you'll have problems when your page displays in other browsers. [ April 02, 2004: Message edited by: Winston Smith ]
for (int i = today; i < endOfTime; i++) { code(); }
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15003
posted
0
This is to give you an idea...
[ April 02, 2004: Message edited by: Eric Pascarello ]