Forum Moderators: open

Message Too Old, No Replies

Validate Javascipt Form

What am I missing ... I know its alot

         

Kate82

6:56 pm on Aug 19, 2005 (gmt 0)

10+ Year Member



Okay, I am a "newbie." I have been working with website for a long time, but I have never been "trained" in computer programming, HTML, anything. Well I have a problem with my company's site. The form on our front page has validation on it, and it works, except when people don't put ANYTHING in. Then it goes right through. What am I doing wrong? Any help would be great.

PS There is nothing in my script I think, but I am going to put everything in here I can think of except for the pl file, that thing is huge.

<script language="JavaScript">
<!--
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr;
for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0;
i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document;
if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++)
x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++)
x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array;
for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc)
x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>


<form method="POST" action="/cgi-bin/formmail.pl">
<h2><table>
<tr><td align="right">Company<td><input type="text" size="15" maxlength="256" name="Company"></tr>

<tr><td align="right">Name<td><input type="text" size="15" maxlength="256" name="realname"></tr>

<tr><td align="right">E-mail <td><input type="text" size="15" maxlength="256" name="email"></tr>

<tr><td align="right">Tel<td><input type="text" size="15" maxlength="256" name="Tel"></tr>

<tr><td align="right">Where did<br>you hear<br>about<br>Legiant? <td><select name="reference"><option selected>Choose One...</option><option>Letter</option><option>Voicemail</option><option>Newsletter</option><option>Postcard</option><option>SME</option><option>APA</option><option>SHRM</option><option>Word of Mouth</option><option>Customer Rep.</option><option>Search Engine</option><option>Paytech</option><option>Other Print</option><option>Other Online</option></select></tr>

</table>

<div align="center">
<input type="hidden" name="recipient" value="webdemo@legiant.com">
<input type="hidden" name="subject" value="Web Demo Request - Front Page">
<input type="hidden" name="redirect" value="http://www.legiant.com/pages/contact_us_confirmation_webdemo.htm">
<input type="submit" name="mailto" onClick="MM_validateForm('reference','','R','Company','','R','realname','','R','email','','R','Tel','','R');return document.MM_returnValue" value="Submit" >
</div>

</h2>
</form>

Don_Hoagie

7:20 pm on Aug 19, 2005 (gmt 0)

10+ Year Member



I don't see anything in here about validating a form; in fact, the only thing you have related to the form is a maxlength characteristic in the HTML, not in the script. If this is the right snippet of code, then it's certainly not validating anything.

Also, as you are new to JavaScript (hey, me too! Let's party), what would you define "validation" as? If someone can get through your form without having to put in any info, then you most likely do not have any "if" statements in place, meaning it doesn't really validate any information. Someone else please correct me if i'm wrong.

kaled

8:33 pm on Aug 19, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



When posting code, try to reformat it to avoid horizontal scrolling.

The function MM_validateForm is missing from your post, so it is impossible to diagnose the problem.

Having said that, the validation code may be connected wrongly. Generally, validation code should be connected to the onsubmit event of the <form> rather than the onclick event of the submit button (but sometimes this is not possible if advanced tricks are being used).

Kaled.