...

View Full Version : Validation Script Stopped Working..



bridgey
08-07-2008, 05:47 PM
Hi All

I have the following javascript in place to check form entry fields before submitting the information to a php script, which emails the info to me.

The problem is that the validation has suddenly stopped working.. it worked half an hour ago before i starting changing the script.. now doesnt. I have been trying to get the script to notice that if a form field is equal to xx, then do not allow submission of the form.

Can anyone see any errors in the below?

The page can be viewed at www.centurysoftware.co.uk/custupdate.html



<script type="text/javascript">
function validate_required(field,alerttxt)
{
with (field)
{
if (value==null||value==""||value=xx)
{alert(alerttxt);return false;}
else {return true}
}
}
function validate_form(form1){
with (form1){
if (validate_required(name,"Please enter your name before proceeding")==false)
{name.focus();return false;}
if (validate_required(client,"Please enter the company name before proceeding")==false)
{client.focus();return false;}
if (validate_required(job,"Please enter your job title before proceeding")==false)
{job.focus();return false;}
if (validate_required(supstatus,"Please select from the following before proceeding..")==false)
{supstatus.focus();return false;}
if (validate_required(email,"Please enter your email address before proceeding")==false)
{email.focus();return false;}
if (validate_required(tel,"Please enter your telephone number before proceeding")==false)
{tel.focus();return false;}
if (validate_required(servos,"Please select from the following before proceeding..")==false)
{servos.focus();return false;}
if (validate_required(servname,"Please enter the computer name of your Sage server before proceeding")==false)
{servname.focus();return false;}
if (validate_required(bit,"Please select from the following before proceeding..")==false)
{bit.focus();return false;}
if (validate_required(mem,"Please select from the following before proceeding..")==false)
{mem.focus();return false;}
if (validate_required(pro,"Please select from the following before proceeding..")==false)
{pro.focus();return false;}
if (validate_required(sql,"Please select from the following before proceeding..")==false)
{sql.focus();return false;}

}
}
</script>


Here is a snippet of the form in use (still called form1):-


<form name="form1" method="post" action="" onsubmit="return validate_form(this);">

<p><span class="style6"><span class="style16">*</span> </span>Please specify the server operating system of your Sage server:<br />
<select name="servos" id="servos" style="border:thin #000000; background-color:#E6FFDD; outline:none; font-family:tahoma; font-size:14px">
<option value="xx" selected="selected">Please Select...</option>
<option value="xx">&nbsp;</option>
<option value="xx">* Windows Server 2008 Family:-</option>
<option value="2008 Standard">Windows Server 2008 Standard Edition</option>
<option value="2008 Enterprise">Windows Server 2008 Enterprise Edition</option>
<option value="2008 Datacenter">Windows Server 2008 Datacenter Edition</option>
<option value="2008 Datacenter">Windows Small Business Server 2008</option>
<option value="xx">&nbsp;</option>
<option value="xx">* Windows Server 2003 Family:-</option>
<option value="2003 SBS">Windows Server 2003 Small Business Edition</option>
<option value="2003 Standard">Windows Server 2003 Standard Edition</option>
<option value="2003 Enterprise">Windows Server 2003 Enterprise Edition</option>
<option value="2003 Datacenter">Windows Server 2003 Datacenter Edition</option>
<option value="xx">&nbsp;</option>
<option value="xx">* Windows Server 2000 Family:-</option>
<option value="2000 Server">Windows 2000 Server</option>
<option value="2000 Advanced Server">Windows 2000 Advanced Server</option>
<option value="2000 Datacenter">Windows 2000 Datacenter Server</option>
<option value="xx">&nbsp;</option>
<option value="xx">&nbsp;</option>
<option value="No Server (P2P)">No Server (Peer to Peer Setup)</option>
<option value="No Server (Standalone)">No Server (Standalone Setup)</option>
</select>


As you can see, I have used options with values of xx for display only. If any of these are selected I do not want to allow submission of the form.

Any ideas?

Many thanks in advance,
Scott

abduraooft
08-07-2008, 05:51 PM
if (value==null||value==""||value=xx)Any clues?

PS: if xx is a string , then you need to use quotes around it.

bridgey
08-07-2008, 06:02 PM
I did try with the following but it didnt work - nothing changed

if (value==null||value==""||value="xx")

abduraooft
08-07-2008, 06:06 PM
It should be value=="xx"

bridgey
08-07-2008, 08:09 PM
you know, i really should stop doing 50 things at once.. maybe i would have noticed that! *embarrassed*

Thanks, works fine :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum